﻿
@{
    ViewData["Title"] = "分析比赛";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<link href="~/assets/css/bootstrap-multiselect.min.css" rel="stylesheet" />
<link href="~/assets/css/jquery-ui.custom.min.css" rel="stylesheet" />
<link href="~/assets/css/jquery-ui.min.css" rel="stylesheet" />
<link href="~/assets/css/ace-rtl.min.css" rel="stylesheet" />
<script src="~/assets/js/bootstrap-multiselect.min.js"></script>
<style>
    .center {
        vertical-align: middle !important;
    }

    .select2-selection--single {
        height: 28px !important;
    }

    .selected {
        background-color: orange !important;
        border: solid;
        border-color: #bf3535;
    }
    .right-result {
    
    color:red!important;
    }
    .border-selected {
        border: 2px solid #6096f7 !important;
    }

    .span-edit {
    background-color:#f7e3b4;
    }
    .tr-hover {
        background-color: #f7f7f7;
        opacity: 50;
    }

    .odd {
        width:60px;
        cursor: pointer;
        padding:0 !important;
    }

    .span-red {
        border-color: green !important;
    }
    .span-green {
        border-color: blue !important;
    }
    .span-blue {
        border-color: red !important;
        line-height: 100% !important;
    }
    .border-solid {
        /*width: calc(100% - 2px);
        height: calc(100% - 2px);*/
        display: inline-block;
        border: 1px solid;
        margin: 1px;
    }

    .border-double {
        /*width: calc(100% - 4px);
        height: calc(100% - 4px);*/
        display: inline-block;
        border: 2px solid;
        margin: 1px;
    }
    .default-span {
        /*width: calc(100% - 4px);
        height: calc(100% - 4px);*/
        display: inline-block;
        margin:2px 2px 2px 2px!important;
        padding:1px 6px 1px 6px;
        line-height:100%!important;
    }



    .background-tr-color {
        background-color: #e4f0fa;
    }

    .countColor1 {
        background-color: #bff5b7;
    }

    .countColor2 {
        background-color: #96b7fb;
    }

   
     .countColor3 {
        background-color: #4bfa21;
    }

    .table-mini tr th {
        padding: 0 3px 0 3px !important;
    }

    .table-mini tr td {
        padding: 0 3px 0 3px !important;
    }

</style>
<div class="breadcrumbs ace-save-state" id="breadcrumbs">
    <ul class="breadcrumb">
        <li>
            <i class="ace-icon fa fa-home home-icon"></i>
            <a href="~/Home/Index">首页</a>
        </li>
        <li>
            <a href="#">投注管理</a>
        </li>
        <li class="active">分析</li>
    </ul>

</div>
<p></p>
<div class="row">
    <div class="col-xs-12">
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-6" style="vertical-align:middle!important; padding:6px 0 0 0;">
                    <button class="btn btn-sm btn-white btn-primary" id="search-Btn" type="button">
                        受注赛程
                    </button>
                    <select id="GameNumberList"></select>
                </div>
                <div class="col-sm-6 " style="vertical-align:middle;text-align:right;padding:0 0 0 0;">


                    <div class="checkbox" style="display:inline-block">
                        <label>
                            <input name="form-field-checkbox" class="ace" id="singleMatchs" type="checkbox">
                            <span class="lbl">单关</span>
                        </label>
                    </div>
                    <div class="checkbox" style="display:inline-block">
                        <label>
                            <input name="form-field-checkbox" class="ace" id="sortChk" type="checkbox">
                            <span class="lbl">排序</span>
                        </label>
                    </div>
                    <div class="btn-group">
                        <button class="btn btn-sm btn-white btn-primary dropdown-toggle" aria-expanded="true" data-toggle="dropdown">
                            策略组
                            <i class="ace-icon fa fa-angle-down icon-on-left"></i>
                        </button>
                        <div class="dropdown-menu dropdown-info dropdown-menu-right"  style="width:300px;padding:20px;">
                            <div id="allStrategyGroups"></div>
                            <hr />
                            <button class="btn btn-sm btn-white btn-primary pull-right" id="filterStrategyGroupBtn" type="button">
                                确定
                            </button>

                        </div>
                    </div>

                    <div class="btn-group">
                        <button class="btn btn-sm btn-white btn-primary dropdown-toggle" aria-expanded="false" data-toggle="dropdown">
                            筛选
                            <i class="ace-icon fa fa-angle-down icon-on-right"></i>
                        </button>
                        <div class="dropdown-menu" style="width:450px;padding:20px;">
                            <label class="pos-rel" data-stopPropagation="true">

                                <span class="lbl">SP</span>
                            </label>
                            <div id="SPDiv">
                                <label class="pos-rel" data-stopPropagation="true">
                                    <input class="ace oddValueChk" type="checkbox" checked="checked" value="1.0">
                                    <span class="lbl">1.0-1.6</span>
                                </label>&nbsp;&nbsp;&nbsp;&nbsp;
                                <label class="pos-rel" data-stopPropagation="true">
                                    <input class="ace oddValueChk" type="checkbox" checked="checked" value="1.6">
                                    <span class="lbl">1.6-2.1</span>
                                </label>&nbsp;&nbsp;&nbsp;&nbsp;
                                <label class="pos-rel" data-stopPropagation="true">
                                    <input class="ace oddValueChk" type="checkbox" checked="checked" value="2.1">
                                    <span class="lbl">2.1-2.6</span>
                                </label>&nbsp;&nbsp;&nbsp;&nbsp;
                                <label class="pos-rel" data-stopPropagation="true">
                                    <input class="ace oddValueChk" type="checkbox" checked="checked" value="2.6">
                                    <span class="lbl">2.6-3.1</span>
                                </label>&nbsp;&nbsp;&nbsp;&nbsp;<br />
                                <label class="pos-rel" data-stopPropagation="true">
                                    <input class="ace oddValueChk" type="checkbox" checked="checked" value="3.1">
                                    <span class="lbl">3.1-3.6</span>
                                </label>&nbsp;&nbsp;&nbsp;&nbsp;
                                <label class="pos-rel" data-stopPropagation="true">
                                    <input class="ace oddValueChk" type="checkbox" checked="checked" value="3.6">
                                    <span class="lbl">3.6-4.1</span>
                                </label>&nbsp;&nbsp;&nbsp;&nbsp;
                                <label class="pos-rel" data-stopPropagation="true">
                                    <input class="ace oddValueChk" type="checkbox" checked="checked" value="4.1">
                                    <span class="lbl">4.1-6.0</span>
                                </label>&nbsp;&nbsp;&nbsp;&nbsp;
                                <label class="pos-rel" data-stopPropagation="true">
                                    <input class="ace oddValueChk" type="checkbox" checked="checked" value="6.0">
                                    <span class="lbl">6.0-999.0</span>
                                </label>

                            </div>
                            <hr style="margin:4px;" />
                            <label class="pos-rel" data-stopPropagation="true">

                                <span class="lbl">日期</span>
                            </label>
                            <div id="DateDiv">

                            </div>
                            <hr style="margin:4px;" />
                            <label class="pos-rel" data-stopPropagation="true">

                                <span class="lbl">让球</span>
                            </label>

                            @*<label class="pos-rel pull-right" data-stopPropagation="true">
                    <input type="checkbox" checked="checked" />
                    <span class="lbl">全选</span>
                </label>*@

                            <div id="RQDiv">

                            </div>

                            <hr style="margin:4px;" />
                            <label class="pos-rel" data-stopPropagation="true">

                                <span class="lbl">赛类</span>
                            </label>

                            <label class="pos-rel pull-right" data-stopPropagation="true">
                                <input type="checkbox" id="checkedAllLeagues" checked="checked" />
                                <span class="lbl">全选</span>
                            </label>

                            <div id="LeagueDiv">

                            </div>
                        </div>
                    </div>
                    <div class="btn-group">
                        <button class="btn btn-sm btn-white btn-primary dropdown-toggle" aria-expanded="false" data-toggle="dropdown">
                            订制列
                            <i class="ace-icon fa fa-angle-down icon-on-right"></i>
                        </button>
                        <div class="dropdown-menu" id="columnDiv" style="width:300px;padding:20px;">
                            <label class="pos-rel" data-stopPropagation="true">
                                <input class="ace" type="checkbox" value="WuBaiID">
                                <span class="lbl">500ID</span>
                            </label>
                            <label class="pos-rel" data-stopPropagation="true">
                                <input class="ace" type="checkbox" checked="checked" value="DateTime">
                                <span class="lbl">时间</span>
                            </label>
                            <label class="pos-rel" data-stopPropagation="true">
                                <input class="ace" type="checkbox" checked="checked" value="Score">
                                <span class="lbl">比分</span>
                            </label>
                            <label class="pos-rel" data-stopPropagation="true">
                                <input class="ace" type="checkbox" checked="checked" value="OddCount">
                                <span class="lbl">样本</span>
                            </label>
                            <label class="pos-rel" data-stopPropagation="true">
                                <input class="ace" type="checkbox" value="YiJia">
                                <span class="lbl">欧赔概率溢价</span>
                            </label>
                            <label class="pos-rel" data-stopPropagation="true">
                                <input class="ace" type="checkbox" value="NiHe">
                                <span class="lbl">拟合概率</span>
                            </label>
                            <label class="pos-rel" data-stopPropagation="true">
                                <input class="ace" type="checkbox" checked="checked" value="CeLue">
                                <span class="lbl">策略系数</span>
                            </label>
                            <label class="pos-rel" data-stopPropagation="true">
                                <input class="ace" type="checkbox" value="KeKao">
                                <span class="lbl">可靠性</span>
                            </label>

                            <hr style="margin:4px;" />
                            <button class="btn btn-sm btn-white btn-primary right" id="hiddenColumnBtn" type="button">
                                确定
                            </button>
                        </div>


                        @*<ul class="dropdown-menu">
                <li>
                    <a href="#">Action</a>
                </li>
                <li>
                    <a href="#">Another action</a>
                </li>
                <li>
                    <a href="#">Something else here</a>
                </li>
                <li class="divider"></li>
                <li>
                    <a href="#">Separated link</a>
                </li>
            </ul>*@
                    </div>



                </div>

            </div>
            <p />
            <div class="row">
                <table class="table table-mini table-condensed table-bordered no-footer" id="match-table" role="grid">
                    <thead id="matchData-thead">
                        <tr>
                            <th class="center" rowspan="2">序</th>
                            <th class="center WuBaiID" rowspan="2">500ID</th>
                            <th class="center " rowspan="2">ID</th>
                            <th class="center" rowspan="2">赛事</th>
                            <th class="center DateTime" rowspan="2">时间</th>
                            <th class="center" rowspan="2">主队</th>
                            <th class="center" rowspan="2">客队</th>
                            <th class="center Score" rowspan="2">比分</th>
                            <th class="center" rowspan="2">让球</th>
                            <th class="center" colspan="3">竞彩赔率</th>
                            <th class="center" rowspan="2">返还</th>
                            <th class="center" colspan="3">切片赔率</th>
                            <th class="center OddCount" rowspan="2">样本</th>
                            <th class="center YiJia" colspan="3">欧赔概率溢价</th>
                            <th class="center FanHuan" colspan="3">单项返还</th>
                            <th class="center NiHe" colspan="3">拟合概率</th>
                            <th class="center CeLue" colspan="3">策略系数</th>
                            <th class="center KeKao" colspan="3">可靠性</th>
                        </tr>
                        <tr>
                            <th class="center">胜</th>
                            <th class="center">平</th>
                            <th class="center">负</th>
                            <th class="center">胜</th>
                            <th class="center">平</th>
                            <th class="center">负</th>
                            <th class="center YiJia">胜</th>
                            <th class="center YiJia">平</th>
                            <th class="center YiJia">负</th>
                            <th class="center FanHuan">胜</th>
                            <th class="center FanHuan">平</th>
                            <th class="center FanHuan">负</th>
                            <th class="center NiHe">胜</th>
                            <th class="center NiHe">平</th>
                            <th class="center NiHe">负</th>

                            <th class="center CeLue">胜</th>
                            <th class="center CeLue">平</th>
                            <th class="center CeLue">负</th>
                            <th class="center KeKao">胜</th>
                            <th class="center KeKao">平</th>
                            <th class="center KeKao">负</th>


                        </tr>
                    </thead>
                    <tbody id="matchData-tbody"></tbody>

                </table>
            </div>


        </div>
        <div class="col-sm-3">

            <div class="tabbable">
                
                <ul class="nav nav-tabs padding-10 tab-color-blue background-blue" id="myTab">
                    <li class="active">
                        <a href="#fenbu" data-toggle="tab">

                            推荐
                        </a>
                    </li>

                    <li>
                        <a href="#messages" data-toggle="tab">
                            分析

                        </a>
                    </li>
                    <li>
                        <a href="#ditu" data-toggle="tab">
                            地图

                        </a>
                    </li>

                </ul>
                   
                    <div class="btn-group" style="position:absolute;top:14px;right:11px;">
                        <button class="btn btn-sm btn-white btn-primary dropdown-toggle" aria-expanded="true" data-toggle="dropdown">
                            标签
                            <i class="ace-icon fa fa-angle-down icon-on-left"></i>
                        </button>
                        <div class="dropdown-menu dropdown-info dropdown-menu-right" id="columnDiv" style="width:300px;padding:20px;">

                            <label class="pos-rel" data-stoppropagation="true"><input class="ace" value="-1" id="checkAllBookMark" checked="checked" type="checkbox"><span class="lbl">全选</span></label>
                           
                            <label class="pos-rel pull-right" data-stoppropagation="true"><input class="ace" value="1" type="checkbox" id="liandong"><span class="lbl" style="color:peru">联动</span></label>
                            


                            <hr style="margin:4px;" />
                            <div id="allMarks"></div>
                            <hr style="margin:4px 0 10px 0;" />

                            <button class="btn btn-sm btn-white btn-primary pull-right" id="filterBookMark" type="button">
                                确定
                            </button>

                        </div>
                    </div>
                
                    <div class="tab-content">
                        <div id="fenbu" class="tab-pane fade in active" style="max-height:756px;height:756px; overflow:auto;border:0px!important;">
                            <table class="table table-condensed table-bordered">
                                <thead>
                                    <tr>
                                        @*<th class="center">序号</th>*@
                                        <th class="center" style="width:70px;">ID</th>
                                        <th class="center"><span class="no-user-sp-caption">选项</span></th>
                                        @*<th class="center"><span class="no-user-sp-caption">返还率</span></th>*@
                                        <th class="center" style="width:70px;"><span class="no-user-sp-caption">标签</span></th>
                                        <th class="center"><span class="no-user-sp-caption">SP</span></th>
                                        <th class="center"><span class="no-user-sp-caption">返还</span></th>

                                        <th class="center"><span class="no-user-sp-caption">备注</span></th>


                                        <th width="35"><a title="删除" id="clearList" href="javascript: void(0);"></a></th>
                                    </tr>
                                </thead>
                                <tbody id="selected_list">

                                    @*<tr style="display: table-row;" matchid="105601">

                        <td class="center">1</td>
                        <td class="center">周一001</td>
                        <td class="center">
                                <span class="label label-warning arrowed-in-right arrowed selectedResult" matchid="105601" boddid="271195" result="1" oddvalue="2.52">胜-2.52</span>
                            </td>
                        <td class="center">88.05%</td>
                        <td class="center">返还率高</td>
                        <td class="center"><textarea class="form-control" id="form-field-8" placeholder="Default Text"></textarea></td>
                        <td class="center"><a title="删除" class="deleteSelectedMatch" href="#" matchid="105601" result="1"><i class="glyphicon glyphicon-remove"></i></a></td>
                    </tr>*@




                                </tbody>
                            </table>
                            <div class="pull-right">
                                <button class="btn btn-sm btn-primary" id="btn-save">保存</button>
                            </div>
                        </div>

                        <div id="ditu" class="tab-pane" style="max-height:756px;height:756px; overflow:auto;border:0px!important;">

                            <table class="table table-condensed table-bordered">
                                <thead>
                                    <tr>
                                        @*<th class="center">序号</th>*@
                                        <th class="center">胜</th>
                                        <th class="center">平</th>
                                        <th class="center">负</th>
                                        <th class="center">胜</th>
                                        <th class="center">平</th>
                                        <th class="center">负</th>
                                    </tr>
                                </thead>
                                <tbody id="selected_odd_list">

                                </tbody>
                            </table>


                        </div>
                        <div class="tab-pane" id="messages" style="max-height:756px;height:756px; overflow-y:auto;overflow-x:hidden;">
                            <div class="widget-box">
                                <div class="widget-header">
                                    <h4 class="smaller">
                                        实力
                                    </h4>
                                </div>
                                <div class="widget-body">
                                    <div class="widget-main">

                                        <div id="chart1" style="width:500px;height:300px;"></div>

                                    </div>
                                </div>
                            </div>
                            <div class="widget-box">
                                <div class="widget-header">
                                    <h4 class="smaller">
                                        状态
                                    </h4>

                                </div>
                                <div class="widget-body">
                                    <div class="widget-main">
                                        <div id="chart2" style="width:500px;height:300px;"></div>
                                    </div>
                                </div><!-- /.widget-main -->
                            </div><!-- /.widget-body -->
                        </div>
                    </div>
            </div>
        </div>
    </div>
</div>



<div id="editBookMark-modal" class="hide">

    <label class="pos-rel"><input class="ace" value="-1" id="checkAllBookMark1" type="checkbox"><span class="lbl">全选</span></label>
    <hr style="margin:4px;" />
    <div id="allBookMarks"></div>
    <hr style="margin:4px 0 10px 0;" />
    <div>
        <button class="btn btn-sm btn-primary pull-right" id="saveBookMark">确定</button>&nbsp;&nbsp;

    </div>

</div>

<div id="editRemark-modal" class="hide">
    
        <div>
            <label for="form-field-8">描述</label>
            <textarea class="form-control" id="newRemark" rows="5" placeholder="Default Text"></textarea>
        </div>
    <hr style="margin:4px;" />
    <div>
        <button class="btn btn-sm btn-info pull-right" id="cancleEditRemark" style="margin: 0 5px 0 5px">取消</button>&nbsp;&nbsp;
        <button class="btn btn-sm btn-primary pull-right" id="saveRemark">保存</button>&nbsp;&nbsp;

    </div>
    
</div>

<div id="odd-detail-modal" class="hide">
    <div class="row">
        <div class="col-sm-12">
            <table class="table  table-bordered table-hover" role="grid" id="cutOddMatch-table">
                <thead>
                    <tr>
                        <th class="center">ID</th>
                        <th class="center">公司</th>
                        <th class="center">胜</th>
                        <th class="center">平</th>
                        <th class="center">负</th>
                        <th class="center">返还</th>
                        <th class="center">偏离</th>
                        <th class="center">时间</th>
                    </tr>
                </thead>
                <tbody id="cutOdds-data">
                    <tr>
                        <td class="center">115</td>
                        <td class="center">竞彩之家</td>
                        <td class="center">1.25</td>
                        <td class="center">2.8</td>
                        <td class="center">5.65</td>
                        <td class="center">91.2%</td>
                        <td class="center">3.4</td>
                        <td class="center">18-01-01 12:56:12</td>
                    </tr>

                </tbody>
            </table>
        </div>
    </div>
</div>

<script type="text/javascript">
    var siteType = "自身";
    var SelectedRemarkSelector;
    var SelectedBookMarkSelector;
    var AllDistributionGraph = [];
    var AllMatchs = [];
    var AllAppUser = [];
    var defaultPayOut = 9200;
    var SelectedMatchs = [];
    var betDetailOdds = [];
    var AllBookMarks = [];
    var OldSelectedMatch = [];
    var OddValueArr = [{ min: 1.0, max: 1.6 }, { min: 1.6, max: 2.1 }, { min: 2.1, max: 2.6 }, { min: 2.6, max: 3.1 }, { min: 3.1, max: 3.6 }, { min: 3.6, max: 4.1 }, { min: 4.1, max: 6.0 }, { min: 6.0, max: 999 }];
    var issue = '';
    var SelectedResultObj =
        [
            { id: "1", text: "胜" },
            { id: "2", text: "平" },
            { id: "3", text: "负" },
            { id: "4", text: "让胜" },
            { id: "5", text: "让平" },
            { id: "6", text: "让负" }
        ];
    $(".dropdown-menu").on("click", "[data-stopPropagation]", function (e) {
        e.stopPropagation();
    });

    $(function () {
        $(document).attr("title", "分析");
        GetAllIssues();
        
        GetAllBoomMarks();
        GetAllStrategyGroups();
        $("#search-Btn").click(function () {
            GetRealTimeData();
        })


        $("#checkAllBookMark").change(function () {
            if ($(this).is(":checked")) {
                $("#allMarks .ace").prop("checked", true);
            } else {
                $("#allMarks .ace").removeAttr("checked");
            }
        });

        $("#checkAllBookMark1").change(function () {
            if ($(this).is(":checked")) {
                $("#allBookMarks .ace").prop("checked", true);
            } else {
                $("#allBookMarks .ace").removeAttr("checked");
            }
        });

        $("#GameNumberList").change(function () {
            issue = $(this).val();

            GetMatchDataByIssue(issue);
        });

        $("#hiddenColumnBtn").click(function () {
            var c = $("#columnDiv input:checkbox");
            var checkedValue = [];
            var noCheckedValue = [];
            $.each(c, function (i, n) {
                if ($(n).is(":checked")) {
                    checkedValue.push($(n).val());
                } else {
                    noCheckedValue.push($(n).val());
                }
            });

            $.each(checkedValue, function (i, n) {
                $("#match-table ." + n).show();
            });
            $.each(noCheckedValue, function (i, n) {
                $("#match-table ." + n).hide();
            });


            $("#match-table").chromatable({
                width: "100%",
                height: "780px",
                scrolling: "yes"
            });
        });

        $("#singleMatchs").change(function () {
            var trs = $("#matchData-tbody tr");
            if ($(this).is(":checked")) {
                $.each(trs, function (i, n) {
                    if (!$(n).is(":hidden")) {
                        var date = $(n).attr("CanSingleBet");
                        if (date == "0") {
                            $(n).hide();
                        }
                    }
                });
            } else {
                $.each(trs, function (i, n) {
                    if ($(n).is(":hidden")) {
                        $(n).show();
                    }
                });
            }

            $("#match-table").chromatable({
                width: "100%",
                height: "780px",
                scrolling: "yes"
            });
        });

        $("#firstNextBtn").click(function () {
            $("#oddDetails").fadeIn();


            var detailOdds = [];
            var guoguan = $("input.createOdd:checked");
            $("#selected_detailOdd_list").empty();
            if (guoguan.length > 0) {
                $.each(guoguan, function (i, n) {
                    var value = parseInt($(n).val());
                    if (value == 1) {
                        var odds = MakeBettingDanGuanDetails(SelectedMatchs);
                        detailOdds = detailOdds.concat(odds);
                    } else if (value == 2) {
                        var odds = MakeBetting2X1Details(SelectedMatchs);
                        detailOdds = detailOdds.concat(odds);
                    } else if (value == 3) {

                        var odds = MakeBetting3X1Details(SelectedMatchs);
                        detailOdds = detailOdds.concat(odds);
                    }
                });
                betDetailOdds = new Array();
                $.each(detailOdds, function (i, n) {
                    var sp = 1;
                    var payReturn = 1;
                    $.each(n, function (f, g) {
                        sp = sp * g.SelectedOdds;
                        payReturn = payReturn * (g.SelectedPayReturn / 10000);
                    });

                    var bet = {
                        Index: i,
                        Checked: true,
                        Content: getContentString(n),
                        SP: sp.toFixed(2),
                        PayReturn: payReturn,
                        BetCount: 0,
                        BetDetailOddContents: n
                    }
                    betDetailOdds.push(bet);
                });
                WriteOddTableData();

            }
        });

        $("#sortChk").change(function () {
            var trs = $("#matchData-tbody tr");
            if ($(this).is(":checked")) {
                trs.sort(MatchSortCompareDesc());
                $("#matchData-tbody").empty();
                $("#matchData-tbody").append(trs);
            } else {
                trs.sort(trcompare(0));
                $("#matchData-tbody").empty().append(trs);
            }
        });
        $(document).delegate(".oddValueChk", "change", function () {
            var trs = $("#matchData-tbody tr");
            var value = parseFloat($(this).val());

            var valueModel = OddValueArr.FirstOrDefault(function (x) { return x.min == value; });
            if (!$(this).is(":checked")) {
                $.each(trs, function (i, n) {
                    if (!$(n).is(":hidden")) {
                        var oddValue = parseFloat($(n).children("td").eq(9).html());
                        if (oddValue >= valueModel.min && oddValue < valueModel.max) {
                            $(n).hide();
                        }
                    }
                });

            } else {
                $.each(trs, function (i, n) {
                    if ($(n).is(":hidden")) {
                        var oddValue = parseFloat($(n).children("td").eq(9).html());
                        if (oddValue >= valueModel.min && oddValue < valueModel.max) {
                            $(n).show();
                        }
                    }
                });
            }
        });
        $(document).delegate(".DateChk", "change", function () {
            var trs = $("#matchData-tbody tr");
            var value = $(this).val();


            if (!$(this).is(":checked")) {
                $.each(trs, function (i, n) {
                    if (!$(n).is(":hidden")) {
                        var date = $(n).attr("issue");
                        if (date == value) {
                            $(n).hide();
                        }
                    }
                });

            } else {
                $.each(trs, function (i, n) {
                    if ($(n).is(":hidden")) {
                        var date = $(n).attr("issue");
                        if (date == value) {
                            $(n).show();
                        }
                    }
                });
            }
        });
        $(document).delegate(".RQChk", "change", function () {
            var trs = $("#matchData-tbody tr");
            var value = $(this).val();


            if (!$(this).is(":checked")) {
                $.each(trs, function (i, n) {
                    if (!$(n).is(":hidden")) {
                        var date = $(n).attr("FixOdds");
                        if (date == value) {
                            $(n).hide();
                        }
                    }
                });

            } else {
                $.each(trs, function (i, n) {
                    if ($(n).is(":hidden")) {
                        var date = $(n).attr("FixOdds");
                        if (date == value) {
                            $(n).show();
                        }
                    }
                });
            }
        });
        $(document).delegate(".LeagueChk", "change", function () {
            var trs = $("#matchData-tbody tr");
            var value = $(this).val();
            if (!$(this).is(":checked")) {
                $.each(trs, function (i, n) {
                    if (!$(n).is(":hidden")) {
                        var date = $(n).attr("League");
                        if (date == value) {
                            $(n).hide();
                        }
                    }
                });

            } else {
                $.each(trs, function (i, n) {
                    if ($(n).is(":hidden")) {
                        var date = $(n).attr("League");
                        if (date == value) {
                            $(n).show();
                        }
                    }
                });
            }
        });

        $("#checkedAllLeagues").change(function () {
            if ($(this).is(":checked")) {
                $(".LeagueChk").prop("checked", true);
            } else {
                $(".LeagueChk").removeAttr("checked");
            }
        });

        var timeId;
        $(document).delegate(".linkTo500", "click", function () {
            var matchId = $(this).attr("matchId");
            window.open("http://odds.500.com/fenxi/shuju-" + matchId + ".shtml");
            return false;
        });

        $(document).delegate(".winOdd,.drawOdd,.loseOdd", "dblclick", function () {

            clearTimeout(timeId);

            var matchId = $(this).attr("matchId");
            var result = $(this).attr("result");
            var e = $("#matchData-tbody td[matchId='" + matchId + "'][result='" + result + "']");
            var selector;

            if (currenrUser.colorName == 1) {
                selector = $(e).children("span");
                selector.addClass("span-red");
            } else if (currenrUser.colorName == 2) {
                selector = $(e).children("span").children("span");
                selector.addClass("span-green");
            } else {
                selector = $(e).children("span").children("span").children("span");
                selector.addClass("span-blue");
            }
            if (selector.hasClass("border-solid")) {
                selector.removeClass("border-solid");
            }
            selector.addClass("border-double");
            DataBindSelectedMatch($(this), selector,2);

        });

        $(document).delegate(".editRemark", "click", function () {

            var canEdit = $(this).attr("canEdit");
            if (canEdit == "false") { 
                return;
            }

            SelectedRemarkSelector = $(this);

            $("#newRemark").val($(this).attr("title"));
            var dialog = $("#editRemark-modal").removeClass('hide').dialog({
                modal: true,
                title: '描述编辑',
                title_html: false,
                width: 400,
                height: 260

            });
        });



        $(document).delegate(".editMarks", "click", function () {

            var canEdit = $(this).attr("canEdit");
            if (canEdit == "false") {
                return;
            }

            SelectedBookMarkSelector = $(this);
            var ids = $(this).attr("ids");
            $("#allBookMarks .ace").removeAttr("checked");
            if (ids != "") {
                var arr = ids.split(",");
                $.each(arr, function (i, n) {
                    $("#allBookMarks .ace[value='" + n + "']").prop("checked", "checked");
                });
            }

            var dialog = $("#editBookMark-modal").removeClass('hide').dialog({
                modal: true,
                title: '选择标签',
                title_html: false,
                width: 400,
                height: 170

            });
        });

        $("#saveBookMark").click(function () {
            var checkedBox = $("#allBookMarks .ace:checked");
            var ids = '';
            var str = '';
            $.each(checkedBox, function (i, n) {
                ids += $(n).val();
                str += $(n).parent().find("span").text();
                if (i < checkedBox.length - 1) { 
                    ids += ",";
                    str += ",";
                }
            });

            var matchId = SelectedBookMarkSelector.attr("matchId");
            SelectedMatchs.FirstOrDefault(function (x) { return x.MatchId == parseInt(matchId) && x.CreateAppUserId == currenrUser.id;; }).BookMarksString = ids;
            SelectedBookMarkSelector.attr("ids", ids);
            SelectedBookMarkSelector.attr("title", str);
            SelectedBookMarkSelector.html(str.substring(0, 4));
            $(".ui-dialog-titlebar-close").trigger("click");
        });


        $("#saveRemark").click(function () {
            var remark = $("#newRemark").val();
            var matchId = SelectedRemarkSelector.attr("matchId");
            var match = SelectedMatchs.FirstOrDefault(function (x) { return x.MatchId == matchId && x.CreateAppUserId == currenrUser.id; });
            match.Remark = remark;
            SelectedRemarkSelector.attr("title", remark);
            SelectedRemarkSelector.html((remark==""?"无":remark.substring(0, 2)));
            $(".ui-dialog-titlebar-close").trigger("click");
        });


        $("#cancleEditRemark").click(function () { $(".ui-dialog-titlebar-close").trigger("click"); });

        $(document).delegate(".winOdd,.drawOdd,.loseOdd", "click", function () {
            clearTimeout(timeId);


            var matchId = $(this).attr("matchId");
            var result = $(this).attr("result");
            var e = $("#matchData-tbody td[matchId='" + matchId + "'][result='" + result + "']");

            var f = $(this);
            timeId = setTimeout(function () {

                var selector;
                if (currenrUser.colorName == 1) {
                    selector = $(e).children("span");
                  
                } else if (currenrUser.colorName == 2) {
                    selector = $(e).children("span").children("span");
                    
                } else {
                    selector = $(e).children("span").children("span").children("span");
                    
                }
                if (selector.hasClass("span-red") || selector.hasClass("span-blue") || selector.hasClass("span-green")) {

                    selector.removeClass("span-red");
                    selector.removeClass("span-green");
                    selector.removeClass("span-blue");
                    selector.removeClass("border-double");
                    selector.removeClass("border-solid");

                } else { 
                    if (currenrUser.colorName == 1) {
                        selector.addClass("span-red");

                    } else if (currenrUser.colorName == 2) {
                        selector.addClass("span-green");

                    } else {
                        selector.addClass("span-blue");
                    }


                    selector.addClass("border-solid");
                }         
                DataBindSelectedMatch(f,selector,1);

            }, 200);

            //$(this).toggleClass("border-selected");

            
        });

        $(document).delegate(".deleteSelectedMatch", "click", function () {
            var matchId = $(this).attr("matchId");
            $("#selected_list tr[matchId='" + matchId + "']").remove();
            $("#matchData-tbody tr[matchId='" + matchId + "'] td.winOdd,#matchData-tbody tr[matchId='" + matchId + "'] td.drawOdd,#matchData-tbody tr[matchId='" + matchId + "'] td.loseOdd").removeClass("border-selected");
            var smatch = SelectedMatchs.FirstOrDefault(function (x) { return x.MatchId == parseInt(matchId) && x.CreateAppUserId == currenrUser.id; });
            //SelectedMatchs.Remove(function (x) { return x.matchId == parseInt(matchId); });

            SelectedMatchs.remove(smatch);
            return false;
        });
        //保存选择的比赛
        $("#btn-save").click(function () {
            var cMatch = SelectedMatchs.Where(function (x) { return x.CreateAppUserId == currenrUser.id });

            if (cMatch.length == 0) {
                layer.alert("你没有选择比赛,无法保存");
                return;
            }

            var postData = {
                matchs: cMatch,
                ids: AllMatchs.Select(function (x) { return x.matchId })
            }
            AjaxData("/AnalystSelectedMatch/Edit", postData, "Post", $(this), function (d) {
                if (undefined != d && d.success) {
                    layer.alert("保存成功");

                } else {
                    layer.alert(d.message);
                }
            })

        });

        $("#filterBookMark").click(function () {
            var checkedBookMarks = $("#allMarks").find("input:checked");

            var marksArr = [];
            $.each(checkedBookMarks, function (i, n) {
                marksArr.push($(n).val());
            });
            var sMatchs = [];
            $.each(SelectedMatchs, function (i, n) {

                if (n.BookMarksString.length == 0) {
                    if (marksArr.contains("-1")) { 
                        ck = true;
                    }

                } else {
                    var bks = n.BookMarksString.split(',');
                    var ck = false;
                    $.each(marksArr, function (j, k) {
                        if (bks.contains(k)) {
                            ck = true;
                            return true;
                        }
                    });
                }
                if (ck) {
                    sMatchs.push(n);
                }

            });

            $("#selected_list").empty();
            $(".span-red").removeClass("span-red");
            $(".span-green").removeClass("span-green");
            $(".span-blue").removeClass("span-blue");
            $(".border-solid").removeClass("border-solid");
            $(".border-double").removeClass("border-double");
            $.each(sMatchs, function (i, n) {

                var ss = '';
                if (n.CreateAppUserId == currenrUser.id) {
                    ss += '<tr style="display: table-row;background-color:#fffff0" matchId="' + n.MatchId + '" userId="' + n.CreateAppUserId + '">';
                } else {
                    ss += '<tr style="display: table-row;" matchId="' + n.MatchId + '" userId="' + n.CreateAppUserId + '">';
                }
                //var ss = '<tr style="display: table-row;" matchId="' + n.MatchId + '">';
                ss += '<td class="center" >' + n.DetailSelectedContentsList[0].WeekName + '</td >';
                //ss += '<td class="center">' + match.cutPayOutRate + '</td>';
                ss += '<td class="center">';


                var s = 0;
                var chance = 0;


                var cuser = AllAppUser.FirstOrDefault(function (x) { return x.id == n.CreateAppUserId });


                var bd = n.DetailSelectedContentsList.Where(function (x) { return x.FixOdds == ""; });
                $.each(bd, function (j, k) {
                    //ss += '<span class="label label-warning arrowed-in-right arrowed selectedResult" matchId="' + k.SelectedMatchId + '"  result="' + k.SelectedResult + '" goodLevel="' + k.GoodLevel + '" oddValue="' + k.SelectedOdds + '" chance="' + k.SelectedChance + '">' + SelectedResultObj.FirstOrDefault(function (x) { return x.id == k.SelectedResult }).text + '-' + k.SelectedOdds + '</span>';
                    ss += k.SelectedOdds;
                    if (j < bd.length - 1) {
                        ss += '+';
                    } else {
                        ss += "<br/>";
                    }

                    var pselector = $("#matchData-tbody td[matchId='" + k.SelectedMatchId + "'][result='" + k.SelectedResult + "']");
                    if (cuser.colorName == 1) {
                        selector = $(pselector).children("span");
                        selector.addClass("span-red");
                    } else if (cuser.colorName == 2) {
                        selector = $(pselector).children("span").children("span");
                        selector.addClass("span-green");

                    } else {
                        selector = $(pselector).children("span").children("span").children("span");
                        selector.addClass("span-blue");

                    }
                    if (k.GoodLevel == 1) {
                        selector.addClass("border-solid");
                    } else {
                        selector.addClass("border-double");
                    }
                });

                var rd = n.DetailSelectedContentsList.Where(function (x) { return x.FixOdds != ""; });
                $.each(rd, function (j, k) {
                    //ss += '<span class="label label-warning arrowed-in-right arrowed selectedResult" matchId="' + k.SelectedMatchId + '"  result="' + k.SelectedResult + '" goodLevel="' + k.GoodLevel + '" oddValue="' + k.SelectedOdds + '" chance="' + k.SelectedChance + '">' + SelectedResultObj.FirstOrDefault(function (x) { return x.id == k.SelectedResult }).text + '-' + k.SelectedOdds + '</span>';
                    ss += k.SelectedOdds;
                    if (j < rd.length - 1) {
                        ss += '+';
                    }

                    var pselector = $("#matchData-tbody td[matchId='" + k.SelectedMatchId + "'][result='" + k.SelectedResult + "']");
                    if (cuser.colorName == 1) {
                        selector = $(pselector).children("span");
                        selector.addClass("span-red");
                    } else if (cuser.colorName == 2) {
                        selector = $(pselector).children("span").children("span");
                        selector.addClass("span-green");

                    } else {
                        selector = $(pselector).children("span").children("span").children("span");
                        selector.addClass("span-blue");

                    }
                    if (k.GoodLevel == 1) {
                        selector.addClass("border-solid");
                    } else {
                        selector.addClass("border-double");
                    }
                });


                ss += '</td>';

                var markStr = CreateBookMarkOption(n.BookMarksString);
                ss += '<td class="center"><a href="#" class="editBookMarks" ids="' + n.BookMarksString +'" matchId="' + n.MatchId + '" title="' + markStr + '" canEdit="true">' + (markStr==""?"无": markStr.substring(0,4)) + '</a></td>';
                ss += '<td class="center" >' + n.SP + '</td >';
                ss += '<td class="center" >' + n.ResultChance + '</td >';
                ss += '<td class="center" ><a href="#" canEdit="true" title="' + n.Remark + '" matchId="' + n.MatchId + '" class="editRemark">' + (n.Remark == "" ? "无" : n.Remark.substring(0, 2)) + '</a></td >';
                ss += '  <td class="center">' + (currenrUser.id != n.CreateAppUserId ? "" : '<a title="删除" href="#" matchId="' + n.MatchId + '" class="deleteSelectedMatch"><i class="glyphicon glyphicon-remove"></i></a>') + '</td>';
                ss += '  </tr >';

                $("#selected_list").append(ss);
                //$('.multiselect:last').multiselect('select', n.BookMarksString);

            });

            $("#liandong").trigger("change");
        });

        $("#liandong").change(function () {
            var trs = $("#matchData-tbody tr");
            if ($(this).is(":checked")) {
                $.each(trs, function (i, n) {
                    if ($(n).find("span.span-red").length == 0 && $(n).find("span.span-green").length == 0 && $(n).find("span.span-blue").length == 0) {
                        $(n).hide();
                    }
                });
            } else {
                $.each(trs, function (i, n) {

                    $(n).show();

                });
            }
            $("#match-table").chromatable({
                width: "100%",
                height: "780px",
                scrolling: "yes"
            });
        });

        $("#filterStrategyGroupBtn").click(function () {
            var groupIds = [];
            $.each($("#allStrategyGroups input:checked"), function (i, n) {
                groupIds.push(parseInt($(n).val()));
            });

            var data = {
                issue: issue,
                groupIds:groupIds
            }

            AjaxData("/JCMatch/GetSelectedMatchResults", data, "Post", "", function (d) {
                if (undefined != d && null != d) {
                    if (d.success) {
                        $('#allStrategyGroups .selected').removeClass("selected");
                        $("#allStrategyGroups .CeLue").html("");
                        $("#allStrategyGroups .KeKao").html("");
                        var trs = $("#matchData-tbody tr");

                        $.each(trs, function (i, n) {
                            if (undefined != $(n).attr('matchid') && $(n).attr('matchid') != '') {
                                var matchId = $(n).attr('matchid');
                                var fixOdd = $(n).attr("fixodds") == "" ? "0" : $(n).attr("fixodds");
                                var sMatch = d.data.FirstOrDefault(function (x) { return x.selectedMatchId == parseInt(matchId) });
                                if (undefined != sMatch && null != sMatch) { 

                                    $.each(sMatch.resultList, function (a, b) {
                                        if (b.fixOdds == fixOdd) {
                                            if (b.selectedResult.indexOf("胜") >= 0) {
                                                $(n).find(".cutOdd:eq(0)").addClass("selected");
                                                //$(n).find(".winChance").addClass("selected");
                                                $(n).find(".CeLue:eq(0)").addClass("selected");
                                                $(n).find(".KeKao:eq(0)").addClass("selected");

                                                $(n).find(".CeLue:eq(0)").html(b.coefficientOfStrategy);
                                                $(n).find(".KeKao:eq(0)").html(b.reliability);
                                            } else if (b.selectedResult.indexOf("平") >= 0) {
                                                $(n).find(".cutOdd:eq(1)").addClass("selected");
                                                //$(n).find(".drawChance").addClass("selected");

                                                $(n).find(".CeLue:eq(1)").addClass("selected");
                                                $(n).find(".KeKao:eq(1)").addClass("selected");

                                                $(n).find(".CeLue:eq(1)").html(b.coefficientOfStrategy);
                                                $(n).find(".KeKao:eq(1)").html(b.reliability);
                                            } else {

                                                $(n).find(".cutOdd:eq(2)").addClass("selected");
                                                //$(n).find(".loseChance").addClass("selected");
                                                $(n).find(".CeLue:eq(2)").addClass("selected");
                                                $(n).find(".KeKao:eq(2)").addClass("selected");

                                                $(n).find(".CeLue:eq(2)").html(b.coefficientOfStrategy);
                                                $(n).find(".KeKao:eq(2)").html(b.reliability);
                                            }
                                        }
                                    });
                                }
                            }
                        });

                        $("#match-table").chromatable({
                            width: "100%",
                            height: "780px",
                            scrolling: "yes"
                        });


                    } else {
                        layer.alert(d.message);
                    }
                }

            });
        });

    });

    function WriteDetailContent(match, d) {
        var ss = '';
        if (undefined != d && null != d && d.length > 0) {

            var arr = [], arr1 = [], arr2 = [], arr3 = [], arr4 = [], arr5 = [];
            ss += '<tr>';
            ss += '<td class="center">' + $("#matchData-tbody tr[matchId='" + match.matchId + "'][fixOdds=''] .winOdd").html() + '</td>';
            ss += '<td class="center">' + $("#matchData-tbody tr[matchId='" + match.matchId + "'][fixOdds=''] .drawOdd").html() + '</td>';
            ss += '<td class="center">' + $("#matchData-tbody tr[matchId='" + match.matchId + "'][fixOdds=''] .loseOdd").html() + '</td>';

            $.each(d, function (a, b) {
                if (null != b.betDetailOddList) {
                    $.each(b.betDetailOddList, function (i, n) {
                        if (n.betDetailOddContentsList.Count(function (x) { return x.selectedMatchId == match.matchId && x.selectedResult == 1; }) > 0) {
                            arr.push(n);
                        }

                        if (n.betDetailOddContentsList.Count(function (x) { return x.selectedMatchId == match.matchId && x.selectedResult == 2; }) > 0) {
                            arr1.push(n);
                        }
                        if (n.betDetailOddContentsList.Count(function (x) { return x.selectedMatchId == match.matchId && x.selectedResult == 3; }) > 0) {
                            arr2.push(n);
                        }
                        if (n.betDetailOddContentsList.Count(function (x) { return x.selectedMatchId == match.matchId && x.selectedResult == 4; }) > 0) {
                            arr3.push(n);
                        }
                        if (n.betDetailOddContentsList.Count(function (x) { return x.selectedMatchId == match.matchId && x.selectedResult == 5; }) > 0) {
                            arr4.push(n);
                        }
                        if (n.betDetailOddContentsList.Count(function (x) { return x.selectedMatchId == match.matchId && x.selectedResult == 6; }) > 0) {
                            arr5.push(n);
                        }


                    });
                }
            });


            ss += '<td class="center">' + arr.Sum(function (x) { return x.betCount; }) + '</td>';
            ss += '<td class="center">' + arr1.Sum(function (x) { return x.betCount; }) + '</td>';
            ss += '<td class="center">' + arr2.Sum(function (x) { return x.betCount; }) + '</td>';


            ss += '</tr>';
            ss += '<tr>';
            ss += '<td class="center">' + $("#matchData-tbody tr[matchId='" + match.matchId + "'][fixOdds!=''] .winOdd").html() + '</td>';
            ss += '<td class="center">' + $("#matchData-tbody tr[matchId='" + match.matchId + "'][fixOdds!=''] .drawOdd").html() + '</td>';
            ss += '<td class="center">' + $("#matchData-tbody tr[matchId='" + match.matchId + "'][fixOdds!=''] .loseOdd").html() + '</td>';
            ss += '<td class="center">' + arr3.Sum(function (x) { return x.betCount; }) + '</td>';
            ss += '<td class="center">' + arr4.Sum(function (x) { return x.betCount; }) + '</td>';
            ss += '<td class="center">' + arr5.Sum(function (x) { return x.betCount; }) + '</td>';


            ss += '</tr>';
            ss += "<tr><td colspan='6'>";
            var userArr = [];
            var c = d.GroupBy(function (x) { return x.createOddUserName; });
            $.each(c, function (i, n) {
                var k = { id: n.GroupValue, count: n.Sum(function (x) { return x.betDetailOddList.Sum(function (y) { return y.betCount }) }) };
                userArr.push(k);
            });

            userArr = userArr.OrderByDescending(function (x) { return x.count; });


            $.each(userArr, function (a, b) {

                var cOdd = d.Where(function (x) { return x.createOddUserName == b.id });
                var betDetailOddLists = [];
                $.each(cOdd, function (i, n) {
                    $.each(n.betDetailOddList, function (j, k) {
                        if (k.betDetailOddContentsList.Count(function (x) { return x.selectedMatchId == match.matchId; }) > 0) {
                            betDetailOddLists.push(k);
                        }
                    })
                });

                var c = betDetailOddLists.sort(oddcomparedesc(match.matchId));
                $.each(c, function (j, k) {
                    ss += b.id;
                    ss += "&nbsp;&nbsp;&nbsp;&nbsp;" + GetContentString(k) + "";
                    ss += '<br/>';
                });


            });

            //$.each(d, function (i, n) {
            //    $.each(n.betDetailOddList, function (j, k) {
            //        var dOdd = k.betDetailOddContentsList.FirstOrDefault(function (x) { return x.selectedMatchId == match.matchId; });
            //        if (null != dOdd) {
            //            ss += n.createOddUserName;
            //            ss += "&nbsp;&nbsp;&nbsp;&nbsp;" + GetContentString(k) + "";
            //            ss += '<br/>';
            //        }
            //    });
            //});
            ss += "</td></tr>";
        }
        return ss;
    }


    var oddcomparedesc = function (prop) {

        valueArr = [
            {
                id: 1, value: 1
            },
            {
                id: 4, value: 2
            },
            {
                id: 2, value: 3
            },
            {
                id: 5, value: 4
            },
            {
                id: 3, value: 5
            },
            {
                id: 6, value: 6
            }
        ];
        var mId = parseInt(prop);
        return function (obj1, obj2) {
            var betOdd1 = {};
            var betOdd2 = {};
          

           
            betOdd1 = obj1.betDetailOddContentsList.FirstOrDefault(function (x) { return x.selectedMatchId == mId });
            betOdd2 = obj2.betDetailOddContentsList.FirstOrDefault(function (x) { return x.selectedMatchId == mId });
            if (valueArr.FirstOrDefault(function (x) { return x.id == betOdd1.selectedResult }).value < valueArr.FirstOrDefault(function (x) { return x.id == betOdd2.selectedResult }).value) {
                return -1;
            } else if (valueArr.FirstOrDefault(function (x) { return x.id == betOdd1.selectedResult }).value < valueArr.FirstOrDefault(function (x) { return x.id == betOdd2.selectedResult }).value) {
                return 1;
            } else
            {
                if (obj1.betCount < obj2.betCount)
                {
                    return 1;
                } else if (obj1.betCount > obj2.betCount) {
                    return -1;
                } else
                {
                    if (betOdd1.selectedOdds < betOdd2.selectedOdds)
                    {
                        return 1;
                    } else if (betOdd1.selectedOdds > betOdd2.selectedOdds)
                    {
                        return -1;
                    } else
                    { 
                        return 0;
                    }

                }
            }
        }
    }

    function GetContentString(n) {
        var ss = "";
        var s = "";
        var pay = 1; var r = "";
        if (null != n.betDetailOddContentsList && n.betDetailOddContentsList.Count() > 0) {

            $.each(n.betDetailOddContentsList, function (j, k) {
                r += k.lotteryResults + "";
                pay = pay * k.selectedOdds;
                //if (k.fixOdds == "" || parseInt(k.fixOdds) == 0) {
                //    s += k.weekName + MatchResult.FirstOrDefault(function (x) { return x.id == k.selectedResult }).text;

                //} else {


                //}
                s += k.weekName + MatchResult.FirstOrDefault(function (x) { return x.id == k.selectedResult }).text;
                if (k.lotteryResults == "1") {

                    s += "<span class='red'>" + k.selectedOdds + "</span>";
                } else if (k.lotteryResults == "0") {
                    s += "<span class='blue'>" + k.selectedOdds + "</span>";
                } else {
                    s += k.selectedOdds;

                }
                if (j < n.betDetailOddContentsList.Count() - 1) {
                    s += '|';
                }
            });
        }

        if (r == '1' || r == "11" || r == "1-1" || r == "11-1" || r == "111") {
            ss += n.betCount + "倍<span class='red'>" + pay.toFixed(2) + " </span>" + s;

        } else if (r == "0" || r == '00' || r == '10' || r == '01' || r == '0-1' || r == '11'
            || r == '110' || r == '101' || r == '100' || r == '011' || r == '001' || r == '010' || r == '011'
            || r == '01-1' || r == '00-1' || r == '10-1' || r == '0-1-1'
        ) {
            ss += n.betCount + "倍<span class='blue'>" + pay.toFixed(2) + " </span>&nbsp;" + s;

        } else {
            ss += n.betCount + "倍" + pay.toFixed(2) + "&nbsp; " + s;

        }
        return ss;
    }


    function GetOddBySelectedMatchIds(ids) { 

        $("#selected_odd_list").html("");
        var postData = {
            ids: ids
        }
       
        AjaxData("/Odd/GetOddBySelectedMatchIds", postData, "Post", "", function (d) {
            if (undefined != d && d.success) {
                var odds = d.data;
                var weekNames = AllMatchs.Select(function (x) { return x.matchNumber }).Distinct().OrderBy(function (x) { return x; });
                if (null != weekNames) { 
                    var ss = '';
                    $.each(weekNames, function (i, n) {
                        var match = AllMatchs.FirstOrDefault(function (x) { return x.matchNumber == n; });
                        var odd = odds.Where(function (x) { return x.betDetailOddList.Count(function (y) { return y.betDetailOddContentsList.Count(function (z) { return z.selectedMatchId == match.matchId; }) > 0 }) > 0 });
                        if (odd.length > 0) {
                            ss += '<tr>';
                            ss += '<td colspan="6">' + n + "&nbsp;&nbsp;&nbsp;" + match.homeTeamName + ' VS ' + match.awayTeamName + '</td>';
                            ss += '</tr>';
                            ss += WriteDetailContent(match, odd);

                        }

                    });

                    $("#selected_odd_list").html(ss);
                }
            }
        });
    }

    function DataBindSelectedMatch(e, selector, level) { 
        var matchId = parseInt($(e).attr("matchId"));
        var result = $(e).attr("result");
        var value = $(e).text();
        var payReturn = $(e).attr("payreturn");
        var fixOdd = $(e).attr("fixOdd");
        //var bOddId = $(this).attr("bOddId");
        var chance = $(e).attr("chance");

        e.removeClass("span-edit");

        var ccMatchs = OldSelectedMatch.Where(function (x) { return x.createAppUserId == currenrUser.id });
        if ($(selector).hasClass("span-red") || $(selector).hasClass("span-green") || $(selector).hasClass("span-blue")) {


            if (ccMatchs.Count(function (x) { return x.matchId == matchId }) == 0) {
                e.addClass("span-edit");
            } else {
                var m = ccMatchs.FirstOrDefault(function (x) { return x.matchId == matchId });
                if (m.detailSelectedContentsList.Count(function (x) { return x.goodLevel == level && x.selectedResult == result; }) == 0) {
                    e.addClass("span-edit");
                }
            }

            var match = AllMatchs.FirstOrDefault(function (x) { return x.matchId == parseInt(matchId); });
            var odd = {
                SelectedMatchId: matchId,
                FixOdds: fixOdd,
                WeekName: match.matchNumber,
                SelectedResult: result,
                SelectedOdds: parseFloat(value),
                SelectedPayReturn: payReturn,
                GoodLevel: level,
                SelectedChance: chance
            };

            var smatch = SelectedMatchs.FirstOrDefault(function (x) { return x.MatchId == parseInt(matchId) && x.CreateAppUserId == currenrUser.id; });

            ///增加或者删除集合里的选项
            if (null != smatch) {

                //var span = $(tr).find("span.selectedResult[result='" + result + "']");

                var sOdd = smatch.DetailSelectedContentsList.FirstOrDefault(function (x) { return x.SelectedResult == result; });
                if (null == sOdd) {
                    smatch.DetailSelectedContentsList.push(odd);
                } else {
                    var oodd = smatch.DetailSelectedContentsList.FirstOrDefault(function (x) { return x.SelectedResult == result; });
                    oodd.GoodLevel = level;
                    oodd.SelectedOdds = parseFloat(value);
                    oodd.SelectedPayReturn = payReturn;
                    oodd.SelectedChance = chance
                }


                var s = 0;
                var chance = 0;
                $.each(smatch.DetailSelectedContentsList, function (j, k) {
                    var odd = parseFloat(k.SelectedOdds);
                    var ca = parseFloat(k.SelectedChance);
                    s += 1.0 / odd;
                    chance += ca;
                });
                var sp = Math.round(100.0 / s) / 100;
                chance = Math.round(100 * sp * chance) / 100;

                smatch.SP = sp;
                smatch.ResultChance = chance;


            } else {
                var smatch = {
                    MatchId: matchId,
                    BookMarksString: '',
                    CreateAppUserId: currenrUser.id,
                    DetailSelectedContentsList: [],
                    Remark: '',
                    Issue: match.issue,
                    WeekName: match.matchNumber,
                    SP: parseFloat(value),
                    ResultChance: payReturn
                };
                //var smatch = SelectedMatchs.FirstOrDefault(function (x) { return x.matchId == parseInt(matchId); });
                smatch.DetailSelectedContentsList.push(odd);
                SelectedMatchs.push(smatch);
            }
        }
        else {

            var m = ccMatchs.FirstOrDefault(function (x) { return x.matchId == matchId });

            if (null != m && m.detailSelectedContentsList.Count(function (x) { return x.selectedResult == result; }) > 0) {
                e.addClass("span-edit");
            }
            var smatch = SelectedMatchs.FirstOrDefault(function (x) { return x.MatchId == parseInt(matchId) && x.CreateAppUserId == currenrUser.id; });
            var odd = smatch.DetailSelectedContentsList.FirstOrDefault(function (x) { return x.SelectedResult == result });
            smatch.DetailSelectedContentsList.remove(odd);
            if (smatch.DetailSelectedContentsList.length == 0) {
                SelectedMatchs.remove(smatch);
            } else { 
                var s = 0;
                var chance = 0;
                $.each(smatch.DetailSelectedContentsList, function (j, k) {
                    var odd = parseFloat(k.SelectedOdds);
                    var ca = parseFloat(k.SelectedChance);
                    s += 1.0 / odd;
                    chance += ca;
                });
                var sp = Math.round(100.0 / s) / 100;
                chance = Math.round(100 * sp * chance) / 100;

                smatch.SP = sp;
                smatch.ResultChance = chance;
            }
        }
        

        //渲染右边选中项表格
        var  c = SelectedMatchs.OrderBy(function (x) { return x.Issue; }).ThenBy(function (x) { return x.WeekName.substring(2, 5); });
        $("#selected_list").empty();
        $.each(c, function (i, n) { 
            var ss = '';
            if (n.CreateAppUserId == currenrUser.id) {
                ss += '<tr style="display: table-row;background-color:#fffff0" matchId="' + n.MatchId + '" userId="' + n.CreateAppUserId + '">';
            } else {
                ss += '<tr style="display: table-row;" matchId="' + n.MatchId + '" userId="' + n.CreateAppUserId + '">';
            }
            ss += '<td class="center" >' + n.WeekName + '</td >';
            //ss += '<td class="center">' + match.cutPayOutRate + '</td>';
            ss += '<td class="center">';

            var bd = n.DetailSelectedContentsList.Where(function (x) { return x.FixOdds == ""; });
            $.each(bd, function (j, k) {
                //ss += '<span class="label label-warning arrowed-in-right arrowed selectedResult" matchId="' + k.SelectedMatchId + '"  result="' + k.SelectedResult + '" goodLevel="' + k.GoodLevel + '" oddValue="' + k.SelectedOdds + '" chance="' + k.SelectedChance + '">' + SelectedResultObj.FirstOrDefault(function (x) { return x.id == k.SelectedResult }).text + '-' + k.SelectedOdds + '</span>';
                ss += k.SelectedOdds;
                if (j < bd.length - 1) {
                    ss += '+';
                } else { 
                    ss += "<br/>";
                }
            });

            var rd = n.DetailSelectedContentsList.Where(function (x) { return x.FixOdds != ""; });
            $.each(rd, function (j, k) {
                //ss += '<span class="label label-warning arrowed-in-right arrowed selectedResult" matchId="' + k.SelectedMatchId + '"  result="' + k.SelectedResult + '" goodLevel="' + k.GoodLevel + '" oddValue="' + k.SelectedOdds + '" chance="' + k.SelectedChance + '">' + SelectedResultObj.FirstOrDefault(function (x) { return x.id == k.SelectedResult }).text + '-' + k.SelectedOdds + '</span>';
                ss += k.SelectedOdds;
                if (j < rd.length - 1) {
                    ss += '+';
                }
            });



            ss += '  </td>';
            var bookMarksStr = CreateBookMarkOption(n.BookMarksString);
            ss += '<td class="center"><a href="#" matchId="' + n.MatchId + '"  ids="' + n.BookMarksString +'" title ="' + bookMarksStr + '" class="editMarks" canEdit="true">' + (bookMarksStr==""?"无": bookMarksStr.substring(0,4)) + '</a></td>';
            ss += '<td class="center" >' + n.SP + '</td >';
            ss += '<td class="center" >' + n.ResultChance + '</td >';

            ss += '<td class="center" ><a href="#" canEdit="true" title="' + n.Remark + '" matchId="' + n.MatchId +'" class="editRemark">' + (n.Remark==""?"无": n.Remark.substring(0,2)) + '</a></td >';
            ss += '  <td class="center">' + (currenrUser.id != n.CreateAppUserId ? "" : '<a title="删除" href="#" matchId="' + n.MatchId + '" class="deleteSelectedMatch"><i class="glyphicon glyphicon-remove"></i></a>') + '</td>';
            ss += '  </tr >';

            $("#selected_list").append(ss);
        });

    }


    //function DataBindSelectedMatch1(e, selector,level) {
    //    var matchId = parseInt($(e).attr("matchId"));
    //    var result = $(e).attr("result");
    //    var value = $(e).text();
    //    var payReturn = $(e).attr("payreturn");
    //    var fixOdd = $(e).attr("fixOdd");
    //    //var bOddId = $(this).attr("bOddId");
    //    var chance = $(e).attr("chance");

    //    e.removeClass("span-edit");
    //    var ccMatchs = OldSelectedMatch.Where(function (x) { return x.createAppUserId == currenrUser.id });
    //    if ($(selector).hasClass("span-red") || $(selector).hasClass("span-green") || $(selector).hasClass("span-blue")) {


    //        if (ccMatchs.Count(function (x) { return x.matchId == matchId }) == 0) {
    //            e.addClass("span-edit");
    //        } else {
    //            var m = ccMatchs.FirstOrDefault(function (x) { return x.matchId == matchId });
    //            if (m.detailSelectedContentsList.Count(function (x) { return x.goodLevel == level && x.selectedResult == result; }) == 0) { 
    //                e.addClass("span-edit");
    //            }
    //        }


    //        var tr = $("#selected_list tr[matchId='" + matchId + "'][userId='" + currenrUser.id + "']");

    //        var match = AllMatchs.FirstOrDefault(function (x) { return x.matchId == parseInt(matchId); });
    //        var odd = {
    //            SelectedMatchId: matchId,
    //            FixOdds: fixOdd,
    //            WeekName: match.matchNumber,
    //            SelectedResult: result,
    //            SelectedOdds: parseFloat(value),
    //            SelectedPayReturn: payReturn,
    //            GoodLevel: level,
    //            SelectedChance: chance
    //        };

    //        if (tr.length > 0) {

    //            var span = $(tr).find("span.selectedResult[result='" + result + "']");
    //            var smatch = SelectedMatchs.FirstOrDefault(function (x) { return x.MatchId == parseInt(matchId) && x.CreateAppUserId == currenrUser.id; });
    //            if (span.length == 0) {
    //                $("#selected_list tr[matchId='" + matchId + "'][userId='" + currenrUser.id + "'] td:eq(1)").append('<span class="label label-warning arrowed-in-right arrowed selectedResult" matchId="' + matchId + '" result="' + result + '"   oddValue="' + value + '" chance="' + chance + '">' + SelectedResultObj.FirstOrDefault(function (x) { return x.id == result }).text + '-' + value + '</span>');

    //                smatch.DetailSelectedContentsList.push(odd);


    //                var s = 0;
    //                var chance = 0;
    //                $.each($("#selected_list tr[matchId='" + matchId + "'][userId='" + currenrUser.id + "'] td:eq(1) span"), function (i, n) {
    //                    var odd = parseFloat($(n).attr("oddValue"));
    //                    var ca = parseFloat($(n).attr("chance"));
    //                    s += 1.0 / odd;
    //                    chance += ca;
    //                });
    //                var sp = Math.round(100.0 / s) / 100;
    //                chance = Math.round(100 * sp * chance) / 100;
    //                $("#selected_list tr[matchId='" + matchId + "'][userId='" + currenrUser.id + "'] td:eq(3)").html(sp);
    //                $("#selected_list tr[matchId='" + matchId + "'][userId='" + currenrUser.id + "'] td:eq(4)").html(chance);
    //            } else {
    //                var oodd = smatch.DetailSelectedContentsList.FirstOrDefault(function (x) { return x.SelectedResult == result; });
    //                oodd.GoodLevel = level;
    //            }
    //        } else {
    //            // var match = AllMatchs.FirstOrDefault(function (x) { return x.matchId == matchId; });
    //            var ss = '';

    //            ss += '<tr style="display: table-row;" matchId="' + matchId + '" userId="' + currenrUser.id + '">';
    //            ss += '<td class="center" >' + match.matchNumber + '</td >';
    //            //ss += '<td class="center">' + match.cutPayOutRate + '</td>';
    //            ss += '<td class="center">';
    //            ss += '<span class="label label-warning arrowed-in-right arrowed selectedResult" matchId="' + matchId + '"  result="' + result + '" chance="' + chance + '" oddValue="' + value + '">' + SelectedResultObj.FirstOrDefault(function (x) { return x.id == result }).text + '-' + value + '</span>';
    //            ss += '  </td>';

    //            ss += '<td class="center"><select multiple="multiple" class="multiselect">' + CreateBookMarkOption() + '</select></td>';
    //            ss += '<td class="center">' + value + '</td>';
    //            ss += '  <td class="center">' + payReturn + '</td>';
    //            ss += '<td class="center" ><textarea class="form-control" placeholder="一些描述"></textarea></td >';
    //            ss += '  <td class="center"><a title="删除" href="#" matchId="' + matchId + '" class="deleteSelectedMatch" result="' + result + '"><i class="glyphicon glyphicon-remove"></i></a></td>';
    //            ss += '  </tr >';

    //            $("#selected_list").append(ss);
    //            //$(".multiselect").select2({
    //            //    minimumResultsForSearch: -1
    //            //});
    //            //$('.multiselect').multiselect();
    //            $('.multiselect:last').multiselect({
    //                enableFiltering: false,
    //                enableHTML: true,
    //                buttonClass: 'btn btn-white btn-primary',
    //                templates: {
    //                    button: '<button type="button" class="multiselect dropdown-toggle" data-toggle="dropdown"><span class="multiselect-selected-text"></span> &nbsp;<b class="fa fa-caret-down"></b></button>',
    //                    ul: '<ul class="multiselect-container dropdown-menu"></ul>',
    //                    filter: '<li class="multiselect-item filter"><div class="input-group"><span class="input-group-addon"><i class="fa fa-search"></i></span><input class="form-control multiselect-search" type="text"></div></li>',
    //                    filterClearBtn: '<span class="input-group-btn"><button class="btn btn-default btn-white btn-grey multiselect-clear-filter" type="button"><i class="fa fa-times-circle red2"></i></button></span>',
    //                    li: '<li><a tabindex="0"><label></label></a></li>',
    //                    divider: '<li class="multiselect-item divider"></li>',
    //                    liGroup: '<li class="multiselect-item multiselect-group"><label></label></li>'
    //                }
    //            });

    //            var smatch = {
    //                MatchId: matchId,
    //                BookMarksString: '',
    //                CreateAppUserId: currenrUser.id,
    //                DetailSelectedContentsList: [],
    //                Remark: ''
    //            };
    //            //var smatch = SelectedMatchs.FirstOrDefault(function (x) { return x.matchId == parseInt(matchId); });
    //            smatch.DetailSelectedContentsList.push(odd);
    //            SelectedMatchs.push(smatch);
    //        }
    //    } else {
    //        var td = $("#selected_list tr[matchId='" + matchId + "'][userId='" + currenrUser.id + "'] td:eq(1)");
    //        $(td).children('span[matchId="' + matchId + '"][result="' + result + '"]').remove();


    //        var m = ccMatchs.FirstOrDefault(function (x) { return x.matchId == matchId });

    //        if (null != m && m.detailSelectedContentsList.Count(function (x) { return  x.selectedResult == result; }) > 0) { 
    //            e.addClass("span-edit");
    //        }


    //        if ($(td).children("span").length == 0) {
    //            $(td).parent().remove();
    //        } else {
    //            var s = 0;
    //            var chance = 0;
    //            $.each($("#selected_list tr[matchId='" + matchId + "'][userId='" + currenrUser.id + "'] td:eq(1) span"), function (i, n) {
    //                var odd = parseFloat($(n).attr("oddValue"));
    //                var ca = parseFloat($(n).attr("chance"));
    //                s += 1.0 / odd;
    //                chance += ca;
    //            });
    //            var sp = Math.round(100.0 / s) / 100;
    //            var chance = Math.round(100 * sp * chance) / 100;
    //            $("#selected_list tr[matchId='" + matchId + "'][userId='" + currenrUser.id + "'] td:eq(3)").html(sp);
    //            $("#selected_list tr[matchId='" + matchId + "'][userId='" + currenrUser.id + "'] td:eq(4)").html(chance);
    //        }

    //        var smatch = SelectedMatchs.FirstOrDefault(function (x) { return x.MatchId == parseInt(matchId) && x.CreateAppUserId == currenrUser.id; });
    //        var odd = smatch.DetailSelectedContentsList.FirstOrDefault(function (x) { return x.SelectedResult == result });
    //        smatch.DetailSelectedContentsList.remove(odd);
    //        if (smatch.DetailSelectedContentsList.length == 0) {
    //            SelectedMatchs.remove(smatch);
    //        }
    //    }
    //}


    function GetAllAppUser() {
        AjaxData("/AppUser/GetAllUser", "", "Get", "", function (d) {
            if (undefined != d && null != d) {
                AllAppUser = d.data;
                GetRealTimeData();
            }
        });
    }


    function GetAllStrategyGroups() { 
        $("#allStrategyGroups").empty();
        AjaxData("/JCTestStrategyGroup/GetAllJCTestStrategyGroup", "", "Get", "", function (d) {
            if (undefined != d && null != d) {
                if (d.success) {
                    //AllBookMarks = d.data;
                    var s = '';
                    $.each(d.data, function (i, n) {
                        s += '<label class="pos-rel" data-stoppropagation="true"><input class="ace" value= "' + n.id + '" type= "checkbox"><span class="lbl">' + n.name + '</span></label >';
                    });
                    $("#allStrategyGroups").html(s);
                }
            }
        });
    }

    function GetAllBoomMarks() {

        $("#allMarks,#allBookMarks").empty();
        
        AjaxData("/BookMark/GetAllList", "", "Get", "", function (d) {
            if (undefined != d && null != d) {
                if (d.success) {
                    AllBookMarks = d.data;
                    var ss = '';
                    var s = '<label class="pos-rel" data-stoppropagation="true"><input class="ace" value= "-1" type= "checkbox" checked="checked" ><span class="lbl">无标签</span></label >';
                    $.each(d.data, function (i, n) {
                        s += '<label class="pos-rel" data-stoppropagation="true"><input class="ace" value= "' + n.id + '" type= "checkbox" checked="checked" ><span class="lbl">' + n.markName + '</span></label >';

                        ss += '<label class="pos-rel" data-stoppropagation="true"><input class="ace" value= "' + n.id + '" type= "checkbox" checked="checked" ><span class="lbl">' + n.markName + '</span></label >';
                    });
                    $("#allMarks").html(s);
                    $("#allBookMarks").html(ss);
                }
                GetAllAppUser();
            }
        });
    }

    function GetAnalystSelectedMatchsByMatchIds(ids) {
        var postData = {
            matchIds: ids
        }
        $("#selected_list").empty();
        AjaxData("/AnalystSelectedMatch/GetAnalystSelectedMatchsByMatchIds", postData, "Post", "", function (d) {
            if (undefined != d && d.success) {
                OldSelectedMatch = d.data;
                $.each(d.data.OrderBy(function (x) { return x.issue }).ThenBy(function (x) { return x.weekName.substring(2,5) }), function (i, n) {

                    
                    var smatch = {
                        Id: n.id,
                        MatchId: n.matchId,
                        CreateAppUserId: n.createAppUserId,
                        CreateTime: n.createTime,
                        LastUpdateTime: n.lastUpdateTime,
                        BookMarksString: n.bookMarksString,
                        Remark: n.remark,
                        SP: n.sp,
                        ResultChance:n.resultChance,
                        DetailSelectedContentsList: [],
                        Issue: n.issue,
                        WeekName:n.weekName
                    };

                    var user = AllAppUser.FirstOrDefault(function (x) { return x.id == n.createAppUserId });
                    var ss = '';
                    if (n.createAppUserId == currenrUser.id) {
                        ss += '<tr style="display: table-row;background-color:#fffff0" matchId="' + n.matchId + '" userId="' + n.createAppUserId + '">';
                     } else { 
                        ss += '<tr style="display: table-row;" matchId="' + n.matchId + '" userId="' + n.createAppUserId + '">';
                    }
                    ss += '<td class="center" >' + n.detailSelectedContentsList[0].weekName + '</td >';
                    //ss += '<td class="center">' + match.cutPayOutRate + '</td>';
                    ss += '<td class="center">';

                    var bd = n.detailSelectedContentsList.Where(function (x) { return x.fixOdds == ""; });
                    $.each(bd, function (j, k) {
                       
                        ss += k.selectedOdds;
                        if (j < bd.length - 1) {
                            ss += '+';
                        } else {
                            ss += "<br/>";
                        }

                        var fselector = $("#matchData-tbody td[matchId='" + k.selectedMatchId + "'][result='" + k.selectedResult + "']");
                        var selector;
                        if (user.colorName == 1) {
                            selector = fselector.children("span");
                            selector.addClass("span-red");
                        } else if (user.colorName == 2) {
                            selector = fselector.children("span").children("span");
                            selector.addClass("span-green");
                        } else {
                            selector = fselector.children("span").children("span").children("span");
                            selector.addClass("span-blue");
                        }
                        if (k.goodLevel == 1) {
                            selector.addClass("border-solid");
                        } else {
                            selector.addClass("border-double");
                        }
                        //$("#matchData-tbody td[matchId='" + k.selectedMatchId + "'][result='" + k.selectedResult + "']").addClass("border-selected");
                        var odd = {
                            SelectedMatchId: k.selectedMatchId,
                            FixOdds: k.fixOdds,
                            WeekName: k.weekName,
                            SelectedResult: k.selectedResult,
                            SelectedOdds: k.selectedOdds,
                            SelectedPayReturn: k.selectedPayReturn,
                            AnalystSelectedMatch: k.analystSelectedMatch,
                            GoodLevel: k.goodLevel,
                            SelectedChance: k.selectedChance
                        };
                        smatch.DetailSelectedContentsList.push(odd);

                    });

                    var rd = n.detailSelectedContentsList.Where(function (x) { return x.fixOdds != ""; });
                    $.each(rd, function (j, k) {
                        
                        ss += k.selectedOdds;
                        if (j < rd.length - 1) {
                            ss += '+';
                        }


                        var fselector = $("#matchData-tbody td[matchId='" + k.selectedMatchId + "'][result='" + k.selectedResult + "']");
                        var selector;
                        if (user.colorName == 1) {
                            selector = fselector.children("span");
                            selector.addClass("span-red");
                        } else if (user.colorName == 2) {
                            selector = fselector.children("span").children("span");
                            selector.addClass("span-green");
                        } else {
                            selector = fselector.children("span").children("span").children("span");
                            selector.addClass("span-blue");
                        }
                        if (k.goodLevel == 1) {
                            selector.addClass("border-solid");
                        } else {
                            selector.addClass("border-double");
                        }
                        //$("#matchData-tbody td[matchId='" + k.selectedMatchId + "'][result='" + k.selectedResult + "']").addClass("border-selected");
                        var odd = {
                            SelectedMatchId: k.selectedMatchId,
                            FixOdds: k.fixOdds,
                            WeekName: k.weekName,
                            SelectedResult: k.selectedResult,
                            SelectedOdds: k.selectedOdds,
                            SelectedPayReturn: k.selectedPayReturn,
                            AnalystSelectedMatch: k.analystSelectedMatch,
                            GoodLevel: k.goodLevel,
                            SelectedChance: k.selectedChance
                        };
                        smatch.DetailSelectedContentsList.push(odd);

                    });





                    //$.each(n.detailSelectedContentsList, function (j, k) {
                    //    ss += '<span class="label label-warning arrowed-in-right arrowed selectedResult" matchId="' + k.selectedMatchId + '"  result="' + k.selectedResult + '" goodLevel="' + k.goodLevel + '" oddValue="' + k.selectedOdds + '" chance="' + k.selectedChance+'">' + SelectedResultObj.FirstOrDefault(function (x) { return x.id == k.selectedResult }).text + '-' + k.selectedOdds + '</span>';

                    //    var fselector = $("#matchData-tbody td[matchId='" + k.selectedMatchId + "'][result='" + k.selectedResult + "']");
                    //    var selector;
                    //    if (user.colorName == 1) {
                    //        selector = fselector.children("span");
                    //        selector.addClass("span-red");
                    //    } else if (user.colorName == 2) {
                    //        selector = fselector.children("span").children("span");
                    //        selector.addClass("span-green");
                    //    } else { 
                    //        selector = fselector.children("span").children("span").children("span");
                    //        selector.addClass("span-blue");
                    //    }
                    //    if (k.goodLevel == 1) {
                    //        selector.addClass("border-solid");
                    //    } else { 
                    //        selector.addClass("border-double");
                    //    }
                    //    //$("#matchData-tbody td[matchId='" + k.selectedMatchId + "'][result='" + k.selectedResult + "']").addClass("border-selected");
                    //    var odd = {
                    //        SelectedMatchId: k.selectedMatchId,
                    //        FixOdds: k.fixOdds,
                    //        WeekName: k.weekName,
                    //        SelectedResult: k.selectedResult,
                    //        SelectedOdds: k.selectedOdds,
                    //        SelectedPayReturn: k.selectedPayReturn,
                    //        AnalystSelectedMatch: k.analystSelectedMatch,
                    //        GoodLevel: k.goodLevel,
                    //        SelectedChance: k.selectedChance
                    //    };
                    //    smatch.DetailSelectedContentsList.push(odd);
                    //});

                    SelectedMatchs.push(smatch);
                    ss += '</td>';
                    var bookMarksStr = CreateBookMarkOption(n.bookMarksString);
                    ss += '<td class="center"><a href="#" matchId="' + n.matchId + '"  ids="' + n.bookMarksString +'"  title="' + bookMarksStr + '" class="editMarks" canEdit="' + (currenrUser.id == n.createAppUserId ? true : false) +'">' + (bookMarksStr==""?"无": bookMarksStr.substring(0,4)) + '</a></td>';
                    ss += '<td class="center" >' + n.sp + '</td >';
                    ss += '<td class="center" >' + n.resultChance + '</td >';

                    ss += '<td class="center" ><a title="' + n.remark + '" href="#" matchId="' + n.matchId + '" class="editRemark"  canEdit="' + (currenrUser.id == n.createAppUserId?true:false)+'">' + (n.remark == "" ? "无" : n.remark.substring(0, 2))  + '</a></td >';
                    ss += '  <td class="center">' + (currenrUser.id != n.createAppUserId ? "" : '<a title="删除" href="#" matchId="' + n.matchId + '" class="deleteSelectedMatch"><i class="glyphicon glyphicon-remove"></i></a>') + '</td>';
                    ss += '  </tr >';

                    $("#selected_list").append(ss);
                   
                  

                });
            }
        });
    }

    function GetSelectedMatchOddDataByMatchIds(ids) {
        var postData = {
            ids: ids
        }
        $("#analyst_selected_list").empty();
        AjaxData("/Odd/GetSelectedMatchOddDataByMatchIds", postData, "Post", "", function (d) {
            if (undefined != d && d.success) {
                if (d.data == null) { return; }
                $.each(d.data, function (i, n) {

                    if (n.betCount < 1500) {
                        
                    } else if (n.betCount >= 1500 && n.betCount < 5000) {
                        $("#matchData-tbody tr td[matchId='" + n.matchId + "'][result='" + n.result + "']>span>span>span").addClass("countColor1");
                    } else if (n.betCount >= 5000 && n.betCount < 15000) {
                        $("#matchData-tbody tr td[matchId='" + n.matchId + "'][result='" + n.result + "']>span>span>span").addClass("countColor2");
                    } else { 
                        $("#matchData-tbody tr td[matchId='" + n.matchId + "'][result='" + n.result + "']>span>span>span").addClass("countColor3");
                    }

                });
                GetOddBySelectedMatchIds(ids);
            }
        });
    }



    function CreateBookMarkOption(bookMarks) {
        var s = "";
        if (undefined == bookMarks || null == bookMarks || "" == bookMarks) {
           
        } else {
            var arr = bookMarks.split(',');
            $.each(arr, function (i, n) {
                var mark = AllBookMarks.FirstOrDefault(function (x) { return x.id == parseInt(n); });
                s += mark.markName;
                if (i < arr.length - 1) { 
                    s += ',';
                }
            });
        }
        return s;
    }

    function WriteMatchCategoryPanel() {
        if (AllMatchs.length > 0) {
            //$("#SPDiv").empty();
            $("#DateDiv").empty();
            $("#RQDiv").empty();
            $("#LeagueDiv").empty();
            //$.each(OddValueArr, function (i, n) {
            //    var count = AllMatchs.Count(function (x) {
            //        var brqOdd = x.JCHadOddsList.SingleOrDefault(function (p) { return p.fixedOdds == "" && p.releaseTime == x.JCHadOddsList.Where(function (z) { return z.fixedOdds == "" }).Max(function (z) { return z.releaseTime; }) });
            //        return
            //    })
            //});

            var wMatchGroup = AllMatchs.GroupBy(function (x) { return x.issue; });
            var s = '';
            $.each(wMatchGroup, function (i, n) {
                s += '<label class="pos-rel" data-stopPropagation="true"><input class="ace DateChk" type= "checkbox" checked="checked" value="' + n.GroupValue + '"> <span class="lbl">' + getMyDay(new Date(n.GroupValue)) + '(' + (n.length / 2) + '场)</span></label >&nbsp;&nbsp;&nbsp;&nbsp;';
            });
            $("#DateDiv").html(s);


            var rqMatchGroup = AllMatchs.GroupBy(function (x) {
                //if (null == x.jcHadOddsList) { return null; }

                return x.fixedOdds;
            });
            var ss = '';
            $.each(rqMatchGroup, function (i, n) {
                //if (n.GroupValue != "-1" && n.GroupValue != "+1") { return true; }
                ss += '<label class="pos-rel" data-stopPropagation="true"><input class="ace RQChk" type= "checkbox" checked="checked" value="' + n.GroupValue + '"> <span class="lbl">' + n.GroupValue + '(' + n.length + '场)</span></label >&nbsp;&nbsp;&nbsp;&nbsp;';
            });
            $("#RQDiv").html(ss);

            var leaugeMatchGroup = AllMatchs.GroupBy(function (x) {
                return x.tournamentName;
            });
            var ss = '';
            $.each(leaugeMatchGroup, function (i, n) {

                ss += '<label class="pos-rel" data-stopPropagation="true"><input class="ace LeagueChk" type= "checkbox" checked="checked" value="' + n.GroupValue + '"> <span class="lbl">' + n.GroupValue + '(' + n.length + '场)</span></label >&nbsp;&nbsp;&nbsp;&nbsp;';
                if ((i + 1) % 3 == 0) {
                    ss += '<br/>';
                }
            });
            $("#LeagueDiv").html(ss);
        }
    }

    function GetMatchDataByIssue(issue) {
        var url = "/JCMatch/GetMatchsByIssue?issue=" + issue;

        AjaxData(url, null, "Get", "", function (d) {
            if (d.success) {
                AllMatchs = d.data;
                WriteTableData(d.data);
                ids = d.data.Select(function (x) { return x.matchId; });
            }
        });

    }

    function GetAllIssues() {
        var url = "/JCMatch/GetAllIssue";
        AjaxData(url, null, "Get", "", function (d) {
            if (d.success) {
                var ss = "";
                $.each(d.data, function (i, n) {
                    ss += '<option value="' + n + '" >' + n + '</option>';
                });
                $('#GameNumberList').html(ss);
                $("#GameNumberList").select2();
            }
        });
    }


    function GetRealTimeData() {
        issue = '';
        var url = "/JCMatch/GetNoFinishedMatch";
        AjaxData(url, null, "Get", "", function (d) {
            if (d.success) {
                AllMatchs = d.data;
                WriteTableData(d.data);
                ids = d.data.Select(function (x) { return x.matchId; });
            }
        });
    }


    function CheckRealResult(wholeScore, fixOdd, result) {
        if (null != wholeScore && undefined != wholeScore && wholeScore.length > 0 && fixOdd != "") {
            var scores = wholeScore.split(':');
            var r = parseInt(scores[0]) - parseInt(scores[1]) + parseInt(fixOdd);
            if ((r > 0 && result == 3) || (r == 0 && result == 1) || (r < 0 && result == 0)) {
                return true;
            } else {
                return false;
            }

        } else {
            return false;
        }
    }

    function getMyDay(date) {
        var week;
        if (date.getDay() == 0) week = "星期日"
        if (date.getDay() == 1) week = "星期一"
        if (date.getDay() == 2) week = "星期二"
        if (date.getDay() == 3) week = "星期三"
        if (date.getDay() == 4) week = "星期四"
        if (date.getDay() == 5) week = "星期五"
        if (date.getDay() == 6) week = "星期六"
        return week;
    }




    function GetSelectedOddContent(n) {
        var s = '';
        if (n.homeCount > 0) {
            s += ' <span class="label label-warning arrowed-in-right arrowed">胜</span>';
        }
        if (n.drawCount > 0) {
            s += ' <span class="label label-warning arrowed-in-right arrowed">平</span>';
        }
        if (n.loseCount > 0) {
            s += ' <span class="label label-warning arrowed-in-right arrowed">负</span>';
        }
        if (s.length > 0) { s += '<br/>'; }
        if (n.letBallHomeCount > 0) {
            s += ' <span class="label label-warning arrowed-in-right arrowed">让胜</span>';
        }
        if (n.letBallDrawCount > 0) {
            s += ' <span class="label label-warning arrowed-in-right arrowed">让平</span>';
        }
        if (n.letBallLoseCount > 0) {
            s += ' <span class="label label-warning arrowed-in-right arrowed">让负</span>';
        }

        return s;

    }
    //function WriteTableData(d) {
    //    $('#matchData-tbody').empty();
    //    if (undefined == d || {} == d) { return; }
    //    var ss = "";
    //    var index = 0;
    //    $.each(d, function (i, n) {
    //        var arr1 = new Array();
    //        var arr2 = new Array();
    //        $.each(n.jcHadOddsList, function (c, k) {
    //            if (k.fixedOdds == "") {
    //                arr1.push(k);
    //            } else {
    //                arr2.push(k);
    //            }

    //        });
    //        arr1.sort(compareDesc("releaseTime"));
    //        arr2.sort(compareDesc("releaseTime"));
    //        var brqOdd = arr1.length == 0 ? null : arr1[0];
    //        var rqOdd = arr2.length == 0 ? null : arr2[0];

    //        //var odd = AllDistributionGraph.FirstOrDefault(function (x) { return x.matchId == n.matchId });

    //        if (null == rqOdd || (rqOdd.fixedOdds != "-1" && rqOdd.fixedOdds != "+1")) { return true; }
    //        ss += '<tr MatchId="' + n.matchId + '"   League="' + n.tournamentName + '" Issue="' + n.issue + '" FiveHundredMatchId="' + n.fiveHundredMatchId + '" FixOdds="' + (rqOdd == null ? '' : rqOdd.fixedOdds) + '"  CanSingleBet="' + (brqOdd == null ? '' : brqOdd.canSingleBet) + '"    >';

    //        ss += '<td class="center">' + (index + 1) + '</td>';
    //        ss += '<td class="center WuBaiID">' + n.fiveHundredMatchId + '</td>';
    //        ss += '<td class="center"><span class="showDesc" matchId="' + n.matchId + '">' + n.matchNumber + '</span></td>';
    //        ss += '<td class="center">' + n.tournamentName + '</td>';
    //        ss += '<td class="center DateTime">' + n.matchTime.substring(n.matchTime.indexOf('T') + 1).substring(0, 5) + '</td>';
    //        ss += '<td class="center">' + n.homeTeamName + '</td>';
    //        ss += '<td class="center">' + n.awayTeamName + '</td>';
    //        ss += '<td class="center Score">' + (null == n.wholeScore ? '' : n.wholeScore) + '</td>';
    //        ss += '<td class="center">' + (rqOdd == null ? '' : rqOdd.fixedOdds) + '</td>';


    //        if (null != n.cutOddsList) {

    //            var cutOdd = n.cutOddsList[0];

    //            if (rqOdd.fixedOdds == "-1") {

    //                ss += '<td class="winOdd center ' + (CheckRealResult(n.wholeScore, "0", 3) ? "realResult" : "") + '" fixOdd="0" matchId="' + n.matchId + '" result="1" bOddId="' + brqOdd.oddId + '"  payReturn="' + (cutOdd.myCutWinChance * brqOdd.homeOdds) + '">' + (brqOdd == null ? '' : brqOdd.homeOdds) + '</td>';
    //                //ss += '<td class="drawOdd ' + (CheckRealResult(n.wholeScore, "0", 1) ? "realResult" : "") + '" matchId="' + n.matchId + '"  result="2">' + (brqOdd == null ? '' : brqOdd.drawOdds) + '</td>';
    //                ss += '<td class="loseOdd center ' + (CheckRealResult(n.wholeScore, "0", 0) ? "realResult" : "") + '" fixOdd="' + rqOdd.fixedOdds + '" bOddId="' + rqOdd.oddId + '"  matchId="' + n.matchId + '" result="6" payReturn="' + ((cutOdd.myCutDrawChance + cutOdd.myCutLoseChance) * rqOdd.awayOdds) + '" >' + (rqOdd == null ? '' : rqOdd.awayOdds) + '</td>';
    //            } else {
    //                ss += '<td class="winOdd center ' + (CheckRealResult(n.wholeScore, "0", 3) ? "realResult" : "") + '" fixOdd="' + rqOdd.fixedOdds + '" matchId="' + n.matchId + '" bOddId="' + rqOdd.oddId + '" result="4"  payReturn="' + ((cutOdd.myCutDrawChance + cutOdd.myCutWinChance) * rqOdd.homeOdds) + '">' + (rqOdd == null ? '' : rqOdd.homeOdds) + '</td>';
    //                //ss += '<td class="drawOdd ' + (CheckRealResult(n.wholeScore, "0", 1) ? "realResult" : "") + '" matchId="' + n.matchId + '"  result="2">' + (brqOdd == null ? '' : brqOdd.drawOdds) + '</td>';
    //                ss += '<td class="loseOdd center ' + (CheckRealResult(n.wholeScore, "0", 0) ? "realResult" : "") + '" fixOdd="0"  matchId="' + n.matchId + '" result="3" bOddId="' + brqOdd.oddId + '"  payReturn="' + (cutOdd.myCutLoseChance * brqOdd.awayOdds) + '">' + (brqOdd == null ? '' : brqOdd.awayOdds) + '</td>';
    //            }


    //            if (rqOdd.fixedOdds == "-1") {
    //                ss += '<td class="center">' + Math.round(defaultPayOut * 100 / cutOdd.cutWinChance) / 100 + '</td>';
    //                ss += '<td class="center">' + Math.round(defaultPayOut * 100 / (cutOdd.cutLoseChance + cutOdd.cutDrawChance)) / 100 + '</td>';
    //            } else {

    //                ss += '<td class="center">' + Math.round(defaultPayOut * 100 / (cutOdd.cutWinChance + cutOdd.cutDrawChance)) / 100 + '</td>';
    //                ss += '<td class="center">' + Math.round(defaultPayOut * 100 / (cutOdd.cutLoseChance)) / 100 + '</td>';
    //            }

    //            ss += '<td class="center OddCount">' + cutOdd.baseDataCount + '</td>';
    //        } else {

    //            if (rqOdd.fixedOdds == "-1") {

    //                ss += '<td class="winOdd center ' + (CheckRealResult(n.wholeScore, "0", 3) ? "realResult" : "") + '" matchId="' + n.matchId + '" result="1" >' + (brqOdd == null ? '' : brqOdd.homeOdds) + '</td>';
    //                //ss += '<td class="drawOdd ' + (CheckRealResult(n.wholeScore, "0", 1) ? "realResult" : "") + '" matchId="' + n.matchId + '"  result="2">' + (brqOdd == null ? '' : brqOdd.drawOdds) + '</td>';
    //                ss += '<td class="loseOdd center ' + (CheckRealResult(n.wholeScore, "0", 0) ? "realResult" : "") + '"  matchId="' + n.matchId + '" result="6">' + (rqOdd == null ? '' : rqOdd.awayOdds) + '</td>';
    //            } else {
    //                ss += '<td class="winOdd center ' + (CheckRealResult(n.wholeScore, "0", 3) ? "realResult" : "") + '" matchId="' + n.matchId + '" result="4">' + (rqOdd == null ? '' : rqOdd.homeOdds) + '</td>';
    //                //ss += '<td class="drawOdd ' + (CheckRealResult(n.wholeScore, "0", 1) ? "realResult" : "") + '" matchId="' + n.matchId + '"  result="2">' + (brqOdd == null ? '' : brqOdd.drawOdds) + '</td>';
    //                ss += '<td class="loseOdd center ' + (CheckRealResult(n.wholeScore, "0", 0) ? "realResult" : "") + '"  matchId="' + n.matchId + '" result="3">' + (brqOdd == null ? '' : brqOdd.awayOdds) + '</td>';
    //            }



    //            ss += '<td class="center"></td>';
    //            ss += '<td class="center"></td>';
    //            //ss += '<td>' + (brqOdd == null ? '' : CacuLationPayReturn1(brqOdd.homeOdds, brqOdd.drawOdds, brqOdd.awayOdds)) + '</td>';
    //            ss += '<td class="center"></td>';
    //        }
    //        ss += '<td class="center YiJia">' + Math.round(cutOdd.myCutWinChance - cutOdd.cutWinChance) / 100 + '</td>';
    //        ss += '<td class="center YiJia">' + Math.round(cutOdd.myCutLoseChance - cutOdd.cutLoseChance) / 100 + '</td>';
    //        if (null != n.cutOddsList) {
    //            ss += '<td class="center NiHe">' + Math.round((rqOdd.fixedOdds == "-1" ? cutOdd.myCutWinChance : cutOdd.let1BallsMatchWinChance)) / 100 + '</td>';
    //            ss += '<td class="center NiHe">' + Math.round((rqOdd.fixedOdds == "-1" ? cutOdd.letNegative1BallsMatchWinChance : cutOdd.myCutLoseChance)) / 100 + '</td>';
    //        } else {
    //            ss += '<td class="center NiHe"></td>';
    //            ss += '<td class="center NiHe"></td>';
    //        }

    //        ss += '<td class="center CeLue"></td>';
    //        ss += '<td class="center CeLue"></td>';
    //        ss += '<td class="center KeKao"></td>';
    //        ss += '<td class="center KeKao"></td>';


    //        ss += '</tr>';


    //        index++;
    //    });
    //    $('#matchData-tbody').html(ss);

    //    $("#match-table").chromatable({
    //        width: "100%",
    //        height: "780px",
    //        scrolling: "yes"
    //    });


    //    WriteMatchCategoryPanel();
    //}

    function CaculateMatchResult(hostScore, guestScore, fixOdd) {
        if (hostScore == -1 || guestScore == -1) { return -1; }
        var result = hostScore - guestScore + fixOdd;
        if (result > 0) {
            return 3;
        } else if (result == 0) { 
            return 1;
        }
        else { 
            return 0;
        }
    }


    function WriteTableData(d) {
        $('#matchData-tbody').empty();
        if (undefined == d || {} == d) { return; }
        var ss = "";
        var preMatchId = 0;

        var className = "";
        $.each(d, function (i, n) {

            if (i == 0) { preMatchId = n.matchId; } else {
                if (n.matchId == preMatchId) {

                } else {
                    preMatchId = n.matchId;
                    if (className == "") {
                        className = "background-tr-color";
                    } else {
                        className = "";
                    }

                }
            }
            ss += '<tr MatchId="' + n.matchId + '" class="' + className + '"   League="' + n.tournamentName + '" Issue="' + n.issue + '" FiveHundredMatchId="' + n.fiveHundredMatchId + '" FixOdds="' + n.fixedOdds + '"  CanSingleBet="' + n.canSingleBet + '"    >';

            ss += '<td class="center">' + (n.index) + (n.canSingleBet == "1" ? '<div style="padding:0;margin-top:-8px;margin-left:-3px;border: 0;height:0px;width:0px;float:left"><font style= "color:red;font-weight:bold;font-size:10px;" >单</font ></div >':'') + '</td>';
            ss += '<td class="center WuBaiID">' + n.fiveHundredMatchId + '</td>';
            ss += '<td class="center"><span class="showDesc" matchId="' + n.matchId + '">' + n.matchNumber + '</span></td>';

            if (n.fixedOdds == null || n.fixedOdds == "") {  // 不让球
                ss += '<td class="center">' + n.tournamentName + '</td>';
            } else { 
                ss += '<td class="center"><a style="color:orange;" target="_blank" href="http://liansai.500.com/zuqiu-'+n.fiveSeasonId+'/" >' + n.tournamentName + '</a></td>';
            }
            ss += '<td class="center DateTime">' + n.matchTime + '</td>';

            if (n.fixedOdds == null || n.fixedOdds == "") { // 不让球
                ss += '<td class="center"><a data-teamid="' + n.homeTeamId + '" data-teamname="' + n.homeTeamName + '"  href="../TeamPlayInfo?teamId=' + n.homeTeamId + '&matchId=' + n.fiveHundredMatchId + '"  target="_blank" title="自身页面详细信息">' + n.homeTeamName + '</a></td>';
                ss += '<td class="center"><a data-teamid="' + n.awayTeamId + '" data-teamname="' + n.awayTeamName + '"  href="../TeamPlayInfo?teamId=' + n.awayTeamId + '&matchId=' + n.fiveHundredMatchId + '"  target="_blank" title="自身页面详细信息">' + n.awayTeamName + '</a></td>';
            } else { 
                ss += '<td class="center"><a style="color:orange;" data-teamid="' + n.homeTeamId + '" href="http://liansai.500.com/team/' + n.homeTeamId + '/" target="_blank" title="500页面详细信息">' + n.homeTeamName + '</a></td>';
                ss += '<td class="center"><a style="color:orange;" data-teamid="' + n.awayTeamId + '" href="http://liansai.500.com/team/' + n.awayTeamId + '/" target="_blank" title="500页面详细信息">' + n.awayTeamName + '</a></td>';
            }
            
            if (n.fixedOdds != "") {
                //ss += '<td class="center Score"><a style="color:orange;" class="linkTo500"  matchId="' + n.fiveHundredMatchId + '" href="#">析</a></td>';

                ss += '<td class="center Score"><a style="color:orange;" class="linkTo500"  matchId="' + n.fiveHundredMatchId + '" href="http://odds.500.com/fenxi/shuju-' + n.fiveHundredMatchId + '">析</a></td>';

             } else {
                ss += '<td class="center Score">' + (null == n.wholeScore ? '' : n.wholeScore) + '</td>';
            }
            ss += '<td class="center">' + n.fixedOdds + '</td>';
            if (null == n.homeOdds) {
                ss += '<td class="center odd winOdd"></td>';
                ss += '<td class="center odd drawOdd"></td>';
                ss += '<td class="center odd loseOdd"></td>';
                ss += '<td class="center"></td>';
                ss += '<td class="center cutOdd"></td>';
                ss += '<td class="center cutOdd"></td>';
                ss += '<td class="center cutOdd"></td>';
                ss += '<td class="center OddCount"></td>';
                ss += '<td class="center YiJia"></td>';
                ss += '<td class="center YiJia"></td>';
                ss += '<td class="center YiJia"></td>';
                ss += '<td class="center NiHe"></td>';
                ss += '<td class="center NiHe"></td>';
                ss += '<td class="center NiHe"></td>';
                ss += '<td class="center FanHuan"></td>';
                ss += '<td class="center FanHuan"></td>';
                ss += '<td class="center FanHuan"></td>';
                ss += '<td class="center CeLue"></td>';
                ss += '<td class="center CeLue"></td>';
                ss += '<td class="center CeLue"></td>';
                ss += '<td class="center KeKao"></td>';
                ss += '<td class="center KeKao"></td>';
                ss += '<td class="center KeKao"></td>';
            } else {
                var arr = null == n.wholeScore ? [-1, -1] : n.wholeScore.split(':');
                var result = CaculateMatchResult(parseInt(arr[0]), parseInt(arr[1]), n.fixedOdds == "" ? 0 : parseInt(n.fixedOdds));


                ss += '<td class="center odd winOdd   ' + (result == 3 ?"right-result":"") + '" matchId="' + n.matchId + '" fixOdd="' + n.fixedOdds + '" payReturn="' + n.jcWinPayOut + '" result="' + (n.fixedOdds == "" ? 1 : 4) + '" matchNumber="' + n.matchNumber + '"  chance="' + n.myCutWinChance + '"><span><span><span class="default-span">' + n.homeOdds + '</span></span></span></td>';
                ss += '<td class="center odd drawOdd  ' + (result == 1 ? "right-result" : "") + '" matchId="' + n.matchId + '" fixOdd="' + n.fixedOdds + '" payReturn="' + n.jcDrawPayOut + '" result="' + (n.fixedOdds == "" ? 2 : 5) + '" matchNumber="' + n.matchNumber + '"  chance="' + n.myCutDrawChance + '"><span><span><span class="default-span">' + n.drawOdds + '</span></span></span></td>';
                ss += '<td class="center odd loseOdd  ' + (result == 0 ? "right-result" : "") + '" matchId="' + n.matchId + '" fixOdd="' + n.fixedOdds + '" payReturn="' + n.jcLosePayOut + '" result="' + (n.fixedOdds == "" ? 3 : 6) + '" matchNumber="' + n.matchNumber + '"  chance="' + n.myCutLoseChance + '"><span><span><span class="default-span">' + n.awayOdds + '</span></span></span></td>';
                ss += '<td class="center">' + (null == n.cutPayOutRate ? '' : n.cutPayOutRate) + '</td>';
                ss += '<td class="center cutOdd">' + (null == n.avgEuropWinOdd ? '' : n.avgEuropWinOdd) + '</td>';
                ss += '<td class="center cutOdd">' + (null == n.avgEuropDrawOdd ? '' : n.avgEuropDrawOdd) + '</td>';
                ss += '<td class="center cutOdd">' + (null == n.avgEuropLoseOdd ? '' : n.avgEuropLoseOdd) + '</td>';
                ss += '<td class="center OddCount">' + (n.baseDataCount == 0 ? "" : n.baseDataCount) + '</td>';
                ss += '<td class="center YiJia">' + n.myCutWinDeviate + '</td>';
                ss += '<td class="center YiJia">' + n.myCutDrawDeviate + '</td>';
                ss += '<td class="center YiJia">' + n.myCutLoseDeviate + '</td>';
                ss += '<td class="center FanHuan"   matchId="' + n.matchId + '" fixOdd="' + n.fixedOdds + '" payReturn="' + n.jcWinPayOut + '" result="' + (n.fixedOdds == "" ? 1 : 4) + '"><span><span><span class="default-span">' + n.jcWinPayOut + '</span></span></span></td>';
                ss += '<td class="center FanHuan" matchId="' + n.matchId + '" fixOdd="' + n.fixedOdds + '" payReturn="' + n.jcDrawPayOut + '" result="' + (n.fixedOdds == "" ? 2 : 5) + '"><span><span><span class="default-span">' + n.jcDrawPayOut + '</span></span></span></td>';
                ss += '<td class="center FanHuan" matchId="' + n.matchId + '" fixOdd="' + n.fixedOdds + '" payReturn="' + n.jcLosePayOut + '" result="' + (n.fixedOdds == "" ? 3 : 6) + '"><span><span><span class="default-span">' + n.jcLosePayOut + '</span></span></span></td>';
                ss += '<td class="center NiHe">' + n.myCutWinChance + '</td>';
                ss += '<td class="center NiHe">' + n.myCutDrawChance + '</td>';
                ss += '<td class="center NiHe">' + n.myCutLoseChance + '</td>';
                ss += '<td class="center CeLue">' + (n.winCoefficientOfStrategy == 0 ? "" : n.winCoefficientOfStrategy) + '</td>';
                ss += '<td class="center CeLue">' + (n.drawCoefficientOfStrategy == 0 ? "" : n.drawCoefficientOfStrategy) + '</td>';
                ss += '<td class="center CeLue">' + (n.loseCoefficientOfStrategy == 0 ? "" : n.loseCoefficientOfStrategy) + '</td>';
                ss += '<td class="center KeKao">' + (n.winReliability == 0 ? "" : n.winReliability) + '</td>';
                ss += '<td class="center KeKao">' + (n.drawReliability == 0 ? "" : n.drawReliability) + '</td>';
                ss += '<td class="center KeKao">' + (n.loseReliability == 0 ? "" : n.loseReliability) + '</td>';
            }
            ss += '</tr>';

        });

        $('#matchData-tbody').html(ss);




        WriteMatchCategoryPanel();
        var ids = d.Select(function (x) { return x.matchId }).Distinct();
        GetAnalystSelectedMatchsByMatchIds(ids);
        GetSelectedMatchOddDataByMatchIds(ids);
        
        $("#hiddenColumnBtn").trigger("click");

    }


    var trcompare = function (prop) {
        return function (obj1, obj2) {
            var val1 = parseFloat($(obj1).children("td").eq(prop).html());
            var val2 = parseFloat($(obj2).children("td").eq(prop).html());
            if (val1 < val2) {
                return -1;
            } else if (val1 > val2) {
                return 1;
            } else {
                return 0;
            }
        }
    }
    var trcompareDesc = function (prop) {
        return function (obj1, obj2) {
            var val1 = parseFloat($(obj1).children("td[class='" + prop + "']").eq(0).html());
            var val2 = parseFloat($(obj2).children("td[class='" + prop + "']").eq(0).html());
            if (val1 < val2) {
                return 1;
            } else if (val1 > val2) {
                return -1;
            } else {
                return 0;
            }
        }
    }

    function MatchSortCompareDesc() {
        return function (obj1, obj2) {
            if (obj1 == null || obj2 == null) { return 0; }
            var row1Values = [{
                odd: parseFloat($(obj1).find("td.winOdd").eq(0).html() == "" ? "0" : $(obj1).find("td.winOdd").eq(0).html()),
                celue: parseFloat($(obj1).find("td.CeLue").eq(0).html() == "" ? "0" : $(obj1).find("td.CeLue").eq(0).html()),
                kekao: parseFloat($(obj1).find("td.KeKao").eq(0).html() == "" ? "0" : $(obj1).find("td.KeKao").eq(0).html())
            }, {
                odd: parseFloat($(obj1).find("td.drawOdd").eq(0).html() == "" ? "0" : $(obj1).find("td.drawOdd").eq(0).html()),
                celue: parseFloat($(obj1).find("td.CeLue").eq(1).html() == "" ? "0" : $(obj1).find("td.CeLue").eq(1).html()),
                kekao: parseFloat($(obj1).find("td.KeKao").eq(1).html() == "" ? "0" : $(obj1).find("td.KeKao").eq(1).html())
            }, {
                odd: parseFloat($(obj1).find("td.loseOdd").eq(0).html() == "" ? "0" : $(obj1).find("td.loseOdd").eq(0).html()),
                celue: parseFloat($(obj1).find("td.CeLue").eq(2).html() == "" ? "0" : $(obj1).find("td.CeLue").eq(2).html()),
                kekao: parseFloat($(obj1).find("td.KeKao").eq(2).html() == "" ? "0" : $(obj1).find("td.KeKao").eq(2).html())
            }];

            var row2Values = [{
                odd: parseFloat($(obj2).find("td.winOdd").eq(0).html() == "" ? "0" : $(obj2).find("td.winOdd").eq(0).html()),
                celue: parseFloat($(obj2).find("td.CeLue").eq(0).html() == "" ? "0" : $(obj2).find("td.CeLue").eq(0).html()),
                kekao: parseFloat($(obj2).find("td.KeKao").eq(0).html() == "" ? "0" : $(obj2).find("td.KeKao").eq(0).html())
            }, {
                odd: parseFloat($(obj2).find("td.drawOdd").eq(0).html() == "" ? "0" : $(obj2).find("td.drawOdd").eq(0).html()),
                celue: parseFloat($(obj2).find("td.CeLue").eq(1).html() == "" ? "0" : $(obj2).find("td.CeLue").eq(1).html()),
                kekao: parseFloat($(obj2).find("td.KeKao").eq(1).html() == "" ? "0" : $(obj2).find("td.KeKao").eq(1).html())
            }, {
                odd: parseFloat($(obj2).find("td.loseOdd").eq(0).html() == "" ? "0" : $(obj2).find("td.loseOdd").eq(0).html()),
                celue: parseFloat($(obj2).find("td.CeLue").eq(2).html() == "" ? "0" : $(obj2).find("td.CeLue").eq(2).html()),
                kekao: parseFloat($(obj2).find("td.KeKao").eq(2).html() == "" ? "0" : $(obj2).find("td.KeKao").eq(2).html())
            }];

            var a = row1Values.OrderByDescending(function (x) { return x.celue })[0];
            var b = row2Values.OrderByDescending(function (x) { return x.celue })[0];


            if (a.celue == 0 && b.celue == 0) {
                var val1 = parseFloat($(obj1).children("td").eq(0).html());
                var val2 = parseFloat($(obj2).children("td").eq(0).html());
                if (val1 < val2) {
                    return 1;
                } else if (val1 > val2) {
                    return -1;
                } else {
                    return 0;
                }
            }
            else {
                if (a.celue < b.celue) {
                    return -1;
                } else if (a.celue > b.celue) {
                    return 1;
                } else {
                    if (a.kekao < b.kekao) {
                        return -1;
                    } else if (a.kekao > b.kekao) {
                        return 1;
                    } else {
                        if (a.odd < a.odd) {
                            return 1;
                        } else if (a.odd > b.odd) {
                            return -1;
                        } else {
                            return 0;
                        }
                    }
                }
            }
        }
    }




    var compare = function (prop) {
        return function (obj1, obj2) {
            var val1 = obj1[prop];
            var val2 = obj2[prop];
            if (val1 < val2) {
                return -1;
            } else if (val1 > val2) {
                return 1;
            } else {
                return 0;
            }
        }
    }
    var compareDesc = function (prop) {
        return function (obj1, obj2) {
            var val1 = obj1[prop];
            var val2 = obj2[prop];
            if (val1 < val2) {
                return 1;
            } else if (val1 > val2) {
                return -1;
            } else {
                return 0;
            }
        }
    }



</script>


